PostTweet() public static méthode

public static PostTweet ( string username, string password, string tweet ) : void
username string
password string
tweet string
Résultat void
Exemple #1
0
        public void Tweetings()
        {
            var twitter = new Twitter();

            twitter.Follow(2, 1);
            twitter.Follow(3, 1);
            twitter.Follow(4, 1);

            twitter.PostTweet(1, 1);
            twitter.PostTweet(2, 2);
            twitter.PostTweet(3, 3);
            twitter.PostTweet(4, 4);

            twitter.Follow(5, 2);
            twitter.Follow(5, 3);
            twitter.Follow(5, 4);
            twitter.Follow(5, 1);


            Assert.Equal(new[] { 4, 3, 2, 1 }, twitter.GetNewsFeed(5));

            twitter.Unfollow(5, 1);

            Assert.Equal(new[] { 4, 3, 2 }, twitter.GetNewsFeed(5));
        }
        public void RunProblem()
        {
            Twitter t = new Twitter();

            t.PostTweet(1, 1);
            t.PostTweet(1, 2);
            t.PostTweet(2, 1);
            t.PostTweet(2, 2);
        }
Exemple #3
0
        public void Init()
        {
            int     userId     = 0;
            int     tweetId    = 0;
            int     followerId = 0;
            int     followeeId = 0;
            Twitter obj        = new Twitter();

            obj.PostTweet(userId, tweetId);
            IList <int> param_2 = obj.GetNewsFeed(userId);

            obj.Follow(followerId, followeeId);
            obj.Unfollow(followerId, followeeId);
        }
Exemple #4
0
        private static void TwitterMode()
        {
            var twitter = new Twitter(_config, _log);

            // TODO split this into Twitter.Functions()
            if (twitter.GetRemainingRequests() > 0)
            {
                var markov   = new Markov(_log);
                var timeline = twitter.GetStatuses();

                if (timeline.Count == 0)
                {
                    _log.Write("Couldn't fetch any tweet, exiting...");
                    return;
                }

                foreach (var tweet in timeline)
                {
                    markov.AddSentence(tweet);
                }

                // either post a tweet or write X tweets to a file
                var writeFile     = _config.GetBoolValue(ConfigKeys.Preferences_Local);
                var forceLastWord = _config.GetBoolValue(ConfigKeys.Preferences_ForceLastWord);

                if (writeFile)
                {
                    var generatedTweets = new List <string>();

                    for (var i = 0; i < 1000; i++)
                    {
                        generatedTweets.Add(markov.GenerateSentence(220, forceLastWord));
                    }

                    var filePath = Directory.GetCurrentDirectory() + @"\tweets.txt";
                    File.AppendAllLines(filePath, generatedTweets);

                    _log.Write($"Generated tweets written at {filePath}.");
                }
                else
                {
                    twitter.PostTweet(markov.GenerateSentence(250, forceLastWord));
                }
            }
        }
        public TwitterTest()
        {
            Twitter     twitter = Twitter.Instance;
            List <User> user    = new List <User>();

            user.Add(twitter.AddUser("Tom"));
            user.Add(twitter.AddUser("Peter"));
            user.Add(twitter.AddUser("Hans"));
            user.Add(twitter.AddUser("Herbert"));

            Random rand = new Random();

            for (int i = 0; i < 50; i++)
            {
                User u1 = user[rand.Next(0, user.Count)];
                User u2 = user[rand.Next(0, user.Count)];

                if (rand.Next(0, 2) == 0)
                {
                    twitter.Follow(u1.UserId, u2.UserId);
                }
                else
                {
                    twitter.UnFollow(u1.UserId, u2.UserId);
                }
            }

            for (int i = 0; i < 100; i++)
            {
                User u1 = user[rand.Next(0, user.Count)];
                twitter.PostTweet(u1.UserId, "Test Tweet " + i + V + u1.Username);
            }

            twitter.Test();
            for (int i = 0; i < user.Count; i++)
            {
                twitter.GetNewsFeed(user[i].UserId, 10);
            }
        }
Exemple #6
0
        public virtual void Run()
        {
#if !DEBUG
            // Start up check to ensure last tweet isn't recent
            if (TwitterConnection.CheckLastTweetNotRecent(TweetTimer, ScreenName, out SleepCounter))
            {
                Console.WriteLine("{0} - Sleeping until: {1}", ScreenName, Utils.GetLocalTime().AddSeconds(SleepCounter / 1000).ToString("dd/MM/yyyy HH:mm:ss"));
                Thread.Sleep(SleepCounter);
            }
#endif
            while (true)
            {
#if DEBUG
                CurrentTime = DateTime.Parse("2018-09-01 15:05:00");
#else
                CurrentTime = Utils.GetLocalTime();
#endif
                Console.WriteLine("************************************************************");

                // This deals with ensuring that we don't run during quiet housr
                if (TweetTimer.CheckOutOfHours(CurrentTime, out SleepCounter))
                {
                    InTimeZone = false;
                    TimePeriod = "OutOfHours";
                }
                else
                {
                    // Check if we are in a time zone
                    SleepCounter = TweetTimer.CheckTimers(CurrentTime, out TimePeriod, out InTimeZone);

                    // Get latest traffic - We swap the origins and destinations depending on time of day for pessimistic traffic
                    int    result;
                    string origin;
                    string destination;

                    CalculateOriginAndDestination(out origin, out destination);

                    result = TrafficChecker.CheckTrafficDelay(origin, destination);

                    // Patch up the destination. This is because currently I just want to simplify the route
                    //destination = destination == "Bedwas" ? "Caerphilly" : "Ystrad";

                    Console.WriteLine("Traffic delay: {0}mins", result);

                    //Select message to send
                    string hashTags = Messages.HashTags;
                    string message  = Messages.SelectMessage(result);
                    message = Messages.FormatMessage(message, destination, hashTags, result, CurrentTime);
                    Console.WriteLine("Message to send: {0}", message);

#if !DEBUG
                    //Tweet Message
                    Task.Run(() => TwitterConnection.PostTweet(message));
#endif

                    // Ensure our sleep doesn't over shoot!
                    if (!InTimeZone)
                    {
                        SleepCounter = TweetTimer.CheckOverShootTimer(CurrentTime, SleepCounter);
                    }
                }

                // Finally, take a little nap
                Console.WriteLine("{0} - Sleeping until: {1}", ScreenName, CurrentTime.AddSeconds(SleepCounter / 1000).ToString("dd/MM/yyyy HH:mm:ss"));

#if !DEBUG
                Thread.Sleep(SleepCounter);
#else
                Thread.Sleep(1000);
#endif
            }
        }
Exemple #7
0
        public void Run()
        {
            Twitter t = new Twitter();

            //["Twitter","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","postTweet","getNewsFeed"]
            //[[],[1,5],[1,3],[1,101],[1,13],[1,10],[1,2],[1,94],[1,505],[1,333],[1,22],[1,11],[1]]
            t.PostTweet(1, 5);
            t.PostTweet(1, 3);
            t.PostTweet(1, 101);
            t.PostTweet(1, 13);
            t.PostTweet(1, 10);
            t.PostTweet(1, 2);
            t.PostTweet(1, 94);
            t.PostTweet(1, 505);
            t.PostTweet(1, 333);
            t.PostTweet(1, 22);
            t.PostTweet(1, 11);
            var ans = t.GetNewsFeed(1);
        }