예제 #1
0
 public TwitterTweetPageModel()
 {
     Tweets         = new List <TwitterTweetModel>();
     NextPageParams = new Dictionary <string, string>();
     Options        = new TwitterOption();
     HasNext        = false;
 }
예제 #2
0
파일: Twitter.cs 프로젝트: BenDerPan/Tw.Net
        public async Task <TwitterTweetPageModel> GetUserTweetsAsync(TwitterOption option, Dictionary <string, string> paramDict)
        {
            var url = $"{AddressLocator.Web}/search/timeline";

            url = AddressLocator.SanitizeQuery(url, paramDict);
            var htmlSource = await HtmlLoader.TryLoadPageAsync(url, GetRandomProxy(), true, false);

            if (!string.IsNullOrEmpty(htmlSource))
            {
                if (RawTweetPage.TryParse(htmlSource, out var rawPage))
                {
                    var           parser  = new HtmlParser();
                    IHtmlDocument htmlDoc = null;
                    try
                    {
                        htmlDoc = await parser.ParseDocumentAsync(rawPage.ItemsHtml);
                    }
                    catch (Exception)
                    {
                    }

                    if (htmlDoc != null)
                    {
                        if (HtmlExtracter.TryParseTweet(option, htmlDoc, out var pageModel))
                        {
                            pageModel.NextPageParams = new Dictionary <string, string>(paramDict);
                            pageModel.HasNext        = rawPage.HasMoreItems;
                            pageModel.SetMaxPosition(rawPage.MinPosition);
                            pageModel.Options = option;
                            return(pageModel);
                        }
                    }
                }
            }


            return(null);
        }
예제 #3
0
파일: Twitter.cs 프로젝트: BenDerPan/Tw.Net
        public async Task <TwitterTweetPageModel> GetUserTweetsAsync(TwitterOption option, long init = -1)
        {
            var paramDict = new Dictionary <string, string>()
            {
                { "vertical", "default" },
                { "src", "unkn" },
                { "include_available_features", "1" },
                { "include_entities", "1" },
                { "max_position", $"{init}" },
                { "reset_error_state", "false" },
            };

            StringBuilder query = new StringBuilder();

            if (!option.PopularTweets)
            {
                paramDict.Add("f", "tweets");
            }

            if (!string.IsNullOrEmpty(option.Lang))
            {
                paramDict.Add("l", option.Lang);
                paramDict.Add("lang", "en");
            }

            if (!string.IsNullOrEmpty(option.Query))
            {
                query.Append($" from:{option.Query}");
            }

            if (!string.IsNullOrEmpty(option.UserName))
            {
                query.Append($" from:{option.UserName}");
            }

            if (!string.IsNullOrEmpty(option.Geo))
            {
                option.Geo = option.Geo.Replace(" ", "");
                query.Append($" geocode:{option.Geo}");
            }

            if (!string.IsNullOrEmpty(option.Search))
            {
                query.Append($" {option.Search}");
            }
            if (option.Year > 0)
            {
                query.Append($" until:{option.Year}-1-1");
            }
            if (option.Since != null)
            {
                query.Append($" since:{option.Since.Value.ToString("yyyy-MM-dd")}");
            }
            if (option.Until != null)
            {
                query.Append($" until:{option.Until.Value.ToString("yyyy-MM-dd")}");
            }
            if (option.Email)
            {
                query.Append(" \"mail\" OR \"email\" OR");
                query.Append(" \"gmail\" OR \"e-mail\"");
            }
            if (option.Phone)
            {
                query.Append($"  \"phone\" OR \"call me\" OR \"text me\"");
            }
            if (option.Verified)
            {
                query.Append($" filter:verified");
            }
            if (!string.IsNullOrEmpty(option.To))
            {
                query.Append($" to:{option.To}");
            }
            if (!string.IsNullOrEmpty(option.All))
            {
                query.Append($" to:{option.All} OR from:{option.All} OR @{option.All}");
            }
            if (!string.IsNullOrEmpty(option.Near))
            {
                query.Append($" near:\"{option.Near}\"");
            }
            if (option.Images)
            {
                query.Append($" filter:images");
            }
            if (option.Videos)
            {
                query.Append($" filter:videos");
            }
            if (option.Media)
            {
                query.Append($" filter:media");
            }
            if (option.Replies)
            {
                query.Append($" filter:replies");
            }
            if (option.NativeRetweets)
            {
                query.Append($" filter:nativeretweets");
            }
            if (option.MinLikes > 0)
            {
                query.Append($" min_faves:{option.MinLikes}");
            }
            if (option.MinRetweets > 0)
            {
                query.Append($" min_retweets:{option.MinRetweets}");
            }
            if (option.MinReplies > 0)
            {
                query.Append($" min_replies:{option.MinReplies}");
            }

            if (option.Links == "include")
            {
                query.Append(" filter:links");
            }
            else if (option.Links == "exclude")
            {
                query.Append(" exclude:links");
            }


            if (!string.IsNullOrEmpty(option.Source))
            {
                query.Append($" source:\"{option.Source}\"");
            }

            if (!string.IsNullOrEmpty(option.MembersList))
            {
                query.Append($" list:{option.MembersList}");
            }
            if (option.FilterRetweets)
            {
                query.Append(" exclude:nativeretweets exclude:retweets");
            }
            if (!string.IsNullOrEmpty(option.CustomQuery))
            {
                query.Clear();
                query.Append(option.CustomQuery);
            }

            paramDict.Add("q", query.ToString());

            return(await GetUserTweetsAsync(option, paramDict));
        }