Exemple #1
0
 public IEnumerable <ITweet> GetMentionsTimeline(int maxNumberOfTweetsRetrieve, long?maxId = null)
 {
     if (maxId.HasValue)
     {
         var parameter = new MentionsTimelineParameters {
             MaxId = maxId.Value, MaximumNumberOfTweetsToRetrieve = maxNumberOfTweetsRetrieve
         };
         return(Timeline.GetMentionsTimeline(parameter));
     }
     else
     {
         return(Timeline.GetMentionsTimeline(maxNumberOfTweetsRetrieve));
     }
 }
        //ToDo: make this async
        public List <ReportDto> GetMentions(long lastProcessedTweetId)
        {
            var mentionsTimelineParameters = new MentionsTimelineParameters
            {
                MaximumNumberOfTweetsToRetrieve = 100,
            };



            //ToDo: remove magic number (it's default value of long for the first run)
            if (lastProcessedTweetId != 0)
            {
                mentionsTimelineParameters.SinceId = lastProcessedTweetId;
            }



            var mentions = Timeline.GetMentionsTimeline(mentionsTimelineParameters);

            var model = new List <ReportDto>();

            if (mentions != null)
            {
                //ToDo: should remove magic string and read it from settings (#naamn)
                foreach (var mention in mentions.Where(x => x.Hashtags.Any(h => h.Text == "naamn")))
                {
                    var modelItem = new ReportDto()
                    {
                        ReporterTweetId                      = mention.Id,
                        ReporterTweetContent                 = mention.Text,
                        ReporterTwitterScreenName            = mention.CreatedBy.ScreenName,
                        ReporterTwitterUserId                = mention.CreatedBy.Id,
                        SuspiciousAccountTwitterScreenName   = mention.QuotedTweet != null ? mention.QuotedTweet.CreatedBy.ScreenName : mention.InReplyToScreenName,
                        SuspiciousAccountTwitterUserId       = mention.QuotedTweet != null ? mention.QuotedTweet.CreatedBy.Id : mention.InReplyToUserId.Value,
                        SuspiciousTweetContent               = mention.QuotedTweet != null ? mention.QuotedTweet.Text : Tweet.GetTweet(mention.InReplyToStatusId.Value).Text,
                        SuspiciousTweetId                    = mention.QuotedTweet != null ? mention.QuotedTweet.Id : mention.InReplyToStatusId.Value,
                        SuspiciousAccountTwitterUserJoinDate = mention.QuotedTweet != null ? mention.QuotedTweet.CreatedBy.CreatedAt : User.GetUserFromId(mention.InReplyToUserId.Value).CreatedAt,
                        IsDirectMessage                      = false
                    };
                    model.Add(modelItem);
                }
            }

            return(model);
        }
Exemple #3
0
        public List <Mencion> obtenerMenciones()
        {
            List <Mencion> menciones = new List <Mencion>();

            Auth.SetUserCredentials(consumer_key, consumer_secret,
                                    acces_token, acces_token_secret);
            var user = User.GetAuthenticatedUser();
            var mentionsTimelineParameters = new MentionsTimelineParameters();
            var tweets = Timeline.GetMentionsTimeline(mentionsTimelineParameters);

            foreach (var mencion in tweets)
            {
                long   id    = mencion.Id;
                string texto = mencion.Text;
                string foto  = mencion.CreatedBy.ProfileImageUrl400x400;
                menciones.Add(new Mencion(id, texto, foto));
            }
            return(menciones);
        }
Exemple #4
0
 public static IEnumerator MentionsTimeline(Client client, MentionsTimelineParameters parameters, Action <List <Tweet> > callback)
 {
     yield return(client.GET <List <Tweet> > (Helper.BuildRESTURL("statuses/mentions_timeline"), parameters, callback));
 }
Exemple #5
0
        public static void Main(string[] cmdlineArgs)
        {
            if (!File.Exists(_configurationFile))
            {
                Console.WriteLine("No configuration found. Can't continue");
                return;
            }

            if (cmdlineArgs.Contains("--dryrun"))
            {
                _isDryRun = true;
            }

            Console.WriteLine("Dry run: " + _isDryRun);

            _configuration = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(_configurationFile));

            if (_configuration.CacheDir != null && _configuration.CacheDir.Trim().Length > 0)
            {
                _generatedImagesFolder = _configuration.CacheDir;
            }

            if (!Directory.Exists(_generatedImagesFolder))
            {
                Directory.CreateDirectory(_generatedImagesFolder);
            }

            if (File.Exists(_previouslyProcessedTweetsFile))
            {
                _previouslyProcessedTweets = JsonConvert.DeserializeObject <List <long> >(File.ReadAllText(_previouslyProcessedTweetsFile));
            }
            else
            {
                _firstRun = true;
            }

            Auth.SetUserCredentials(
                _configuration.ConsumerKey,
                _configuration.ConsumerSecret,
                _configuration.UserAccessToken,
                _configuration.UserAccessSecret);

            RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackOnly;

            TweetinviEvents.QueryBeforeExecute += (sender, args) =>
            {
                var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);

                if (queryRateLimits != null)
                {
                    if (queryRateLimits.Remaining > 0)
                    {
                        // process
                        return;
                    }

                    args.Cancel = true;
                    System.Console.WriteLine("ERROR: Rate limit hit\nQuery: " + args.QueryURL);
                }
            };

            Console.WriteLine(DateTime.Now);

            var firstPage = true;
            var pageNo    = 1;

            while (true)
            {
                System.Console.WriteLine("Page: " + pageNo++);

                var mentionTLParams = new MentionsTimelineParameters
                {
                    MaximumNumberOfTweetsToRetrieve = _tweetsPerPage
                };

                if (!_firstRun)
                {
                    mentionTLParams.SinceId = _previouslyProcessedTweets.Max();
                }

                if (!firstPage)
                {
                    mentionTLParams.MaxId = _previouslyProcessedTweets.Min() - 1;
                }

                var mentionsTLPage = Timeline.GetMentionsTimeline(mentionTLParams);

                if (mentionsTLPage == null || mentionsTLPage.Count() == 0)
                {
                    System.Console.WriteLine("No mentions to process");
                    break;
                }
                else
                {
                    foreach (var mention in mentionsTLPage)
                    {
                        if (_isDryRun)
                        {
                            ShowMention(mention);
                        }
                        else
                        {
                            ProcessMention(mention);
                        }
                    }
                }

                if (firstPage)
                {
                    firstPage = false;
                }
            }

            File.WriteAllText(_previouslyProcessedTweetsFile, JsonConvert.SerializeObject(_previouslyProcessedTweets));
        }