Пример #1
0
        private static void GetTweets()
        {
            if (AllTweets.Any())
            {
                // Get tweets that have gone up since we last looked.
                var tweets = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()
                {
                    ScreenName = "SnowIsEveryword",
                    Count      = 1000,
                    TrimUser   = true,
                    SinceId    = AllTweets.Last().Id
                });
                // Get tweets older than we have in our records.  This will eventally dry up.
                tweets = tweets.Union(service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()
                {
                    ScreenName = "SnowIsEveryword",
                    Count      = 1000,
                    TrimUser   = true,
                    MaxId      = AllTweets.First().Id
                }));

                {
                    // Slowly Trawl back through older tweets, seeing if we missed some in the middle.
                    if (LatestRetrievedTweetThisSession < 1)
                    {
                        LatestRetrievedTweetThisSession = AllTweets.Last().Id;
                    }
                    var Regrab = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()
                    {
                        ScreenName = "SnowIsEveryword",
                        Count      = 200,
                        TrimUser   = true,
                        MaxId      = LatestRetrievedTweetThisSession
                    });
                    if (Regrab.Any())
                    {
                        LatestRetrievedTweetThisSession = Regrab.LastOrDefault().Id - 1;
                        tweets = tweets.Union(Regrab);
                    }
                }

                var oldnum = AllTweets.Count();
                AllTweets = tweets.Union(AllTweets)
                            .OrderBy(t => t.Id)
                            .ToArray();

                Console.WriteLine($"Tweets before Update: {oldnum}");
                Console.WriteLine($"Tweets after Update:  {AllTweets.Count()}");
                Console.WriteLine($"Diff: {AllTweets.Count() - oldnum}");
            }
            else
            {
                AllTweets = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()
                {
                    ScreenName = "SnowIsEveryword", Count = 1000, TrimUser = true
                }).ToArray();
            }
        }
Пример #2
0
        public async Task Events_are_emitted()
        {
            var cmd    = new AllTweets(take: 5);
            var tweets = await _engine.Execute(cmd);

            Assert.Equal(3, _eventsEmitted.Count);

            Assert.IsType <Tweeted>(_eventsEmitted[0]);
            Assert.Equal(((Tweeted)_eventsEmitted[0]).Tweet, tweets[0]);

            Assert.IsType <Tweeted>(_eventsEmitted[1]);
            Assert.Equal(((Tweeted)_eventsEmitted[1]).Tweet, tweets[1]);
        }
Пример #3
0
        public async Task Tweets_can_be_retrieved_and_have_increasing_ids()
        {
            var cmd    = new AllTweets(take: 5);
            var tweets = await _engine.Execute(cmd);

            Assert.Equal(3, tweets.Length);
            Assert.Equal(1, tweets[0].Id);
            Assert.Equal("bart", tweets[0].UserName);
            Assert.Equal("This is the worst day of my life", tweets[0].Message);
            Assert.Equal(2, tweets[1].Id);
            Assert.Equal("homer", tweets[1].UserName);

            Assert.Equal(3, tweets[2].Id);
            Assert.Equal("bart", tweets[0].UserName);
        }
Пример #4
0
        //*******************************************************************
        // Public method: GetAllTweets()
        // Arguments: None
        // Returns: List<AllTweets>
        // Description: Retrive a generic list of all tweets from a text file
        // Revision: 1.01a
        // Revision date: 2016/05/25
        // ******************************************************************
        public List <AllTweets> GetAllTweets()
        {
            // Initilize List to store Users
            List <Users> usersList = new List <Users>();
            // Initilize List to store Followsers
            List <Followers> followersList = new List <Followers>();
            // Initilize List to store Tweets
            List <Tweets> tweetsList = new List <Tweets>();
            // Initilize List to store AllTweets
            List <AllTweets> allTweetsList = new List <AllTweets>();

            // Initilize instance of UserManager
            UserManager userManager = new UserManager();
            // Initilize instance of TweetManager
            TweetManager tweetManager = new TweetManager();
            // Initilize instance of AllTweets
            AllTweets allTweets = null;

            try
            {
                // Get a list of all users from user.txt file
                usersList = userManager.GetTweetOwnersFromStream();
                // Get a list of all followers from user.txt file
                followersList = userManager.GetTweetFollowersFromStream();
                // Get list of all tweets from tweet.txt file
                tweetsList = tweetManager.GetTweetsByOwnerFromStream();

                // Iterate through all user in usersList
                foreach (Users user in usersList)
                {
                    // Initilize instance of AllTweets
                    allTweets = new AllTweets();
                    // Store sender of tweet
                    allTweets.Owner = user.Owner;
                    // Initilize List to store all tweets from followers
                    allTweets.Tweet = new List <string>();

                    // Check if user has any followers
                    var hasFollowers = followersList.Find(item => item.Owner == user.Owner);

                    // Validate if follows is not null
                    if (hasFollowers != null)
                    {
                        // Check if user has any tweets from followers
                        var hasTweets = tweetsList.Find(item => item.Owner == hasFollowers.Owner);

                        // Validate if tweets is not null
                        if (hasTweets != null)
                        {
                            // Iterate through all the tweets stred in tweetsList
                            foreach (Tweets tweets in tweetsList)
                            {
                                // Check is there are any tweets from sender
                                if (user.Owner == tweets.Owner)
                                {
                                    // Add tweets from sender to allTweets List
                                    allTweets.Tweet.Add("\t@" + tweets.Owner + ": " + tweets.Tweet);
                                }// Check is there are any tweets from gollowers
                                else if (tweets.Owner == hasFollowers.Follower)
                                {
                                    // Add tweets from followers to allTweets List
                                    allTweets.Tweet.Add("\t@" + tweets.Owner + ": " + tweets.Tweet);
                                }
                            }
                        }
                    }

                    // Add tweet transation to allTweetsList
                    allTweetsList.Add(allTweets);
                }
            }catch (Exception ex)
            {
                Console.WriteLine("HelpLink = {0}", ex.HelpLink);
                Console.WriteLine("Message = {0}", ex.Message);
                Console.WriteLine("Source = {0}", ex.Source);
                Console.WriteLine("StackTrace = {0}", ex.StackTrace);
                Console.WriteLine("TargetSite = {0}", ex.TargetSite);
            }

            // Return all tweets stored in allTweetsList
            return(allTweetsList);
        }