예제 #1
0
        // SQL query that will find all rows
        // whose has_been_posted colum = 0
        // so we don't send duplicate tweets

        public List <Twitter> GetTweets()
        {
            using (connection = new MySqlConnection(connectionString))
            {
                // SQL command to check for 0's in the has_been_posted
                // column and return a random selection of posts for
                // the limit set
                // Need to add some randomization to the limit for
                // more humanlike behavior (aka posting)
                string lookForZeros = "SELECT * FROM `imageurls` WHERE `has_been_posted` IN (SELECT `has_been_posted` FROM `imageurls` GROUP BY `has_been_posted` HAVING COUNT(*) > 1) ORDER BY rand() LIMIT @limit";

                // List of tweets not posted yet
                var tweetsNotPosted = new List <Twitter>();

                // Number of tweets to attempt to post

                int limit = Timer.RandomizeNumberOfTweets();
                // int limit = 1;

                using (var cmd = new MySqlCommand(lookForZeros, connection))
                {
                    connection.Open();

                    cmd.Parameters.Add("@limit", MySqlDbType.Int32).Value = limit;
                    var reader = cmd.ExecuteReader();

                    // puts tweets that haven't posted into Twitter object list
                    while (reader.Read())
                    {
                        var twitter = new Twitter
                        {
                            Title = reader[0].ToString(),
                            Image = reader[1].ToString()
                        };

                        tweetsNotPosted.Add(twitter);

                        // update has_been_posted to 1
                        HasBeenPosted(reader[1].ToString());
                    }
                    return(tweetsNotPosted);
                }
            }
        }
예제 #2
0
        // A nice greeting as well as a central place
        // to call all our methods.

        static void Greeting()
        {
            Console.WriteLine("Hello and welcome to the TrumpTweeter 9000!");
            Console.WriteLine("Let's get started. Beep boop boop...");

            // Connects to Reddit and adds new tweets to database.
            // Make this an aysnc process
            var reddit = new Reddit();

            reddit.ConnectToReddit();

            // Opens Db, grabs one Tweet
            // that hasn't been posted and publishes it
            // to Twitter.
            var twitter = new Twitter();

            twitter.NewTweetsAsync();

            Console.ReadKey();
        }