public void C_StatsUpdated(object sender, RetweetEventArgs e) { // Update stats displayed and activate notification if new rank is achieved. --Kris RefreshStats(); if (e != null && !e.NewRank.Equals(e.OldRank) && (e.SourceUser.Equals("BernieSanders") || e.SourceUser.Equals("SenSanders"))) { // Fire notification of new rank. --Kris CrossLocalNotifications.Current.Show("New Rank", "Congratulations! You've earned a new rank: " + e.NewRank); } }
public static void C_StatsUpdated(object sender, RetweetEventArgs e) { Console.WriteLine("[" + DateTime.Now.ToString("F") + "]: Retweet #" + e.Score.ToString() + " from " + e.SourceUser + ": " + e.Tweet); if (!e.NewRank.Equals(e.OldRank) && (e.SourceUser.Equals("BernieSanders") || e.SourceUser.Equals("SenSanders"))) { Console.WriteLine("************************************************************"); Console.WriteLine("Congratulations! You have earned a new rank: " + e.NewRank); Console.WriteLine("************************************************************"); } else { Console.WriteLine("[Current Rank: " + e.NewRank + "]"); } }
private void ControlLoop() { // Every hour, check followed Twitter accounts for new tweets and retweet. Limit 10 retweets per hour to avoid spam. --Kris while (Active) { if (ScriptMode || !LastCheck.HasValue || LastCheck.Value.AddHours(1) < DateTime.Now) { int i = 0; LoadTimelines(); foreach (KeyValuePair <string, IEnumerable <ITweet> > pair in Tweets) { foreach (ITweet tweet in pair.Value) { if (!RetweetHistory.ContainsKey(tweet.Url) && tweet.CreatedAt.AddDays(1) > DateTime.Now) { string oldRank = GetRank(TwitterUserFullnames[pair.Key]); if (!TestMode) { Tweet.PublishRetweet(tweet); } RetweetHistory.Add(tweet.Url, pair.Key); SaveRetweetHistory(); if (Targets[TwitterUserFullnames[pair.Key]].Stats.Retweets.Equals(0)) { Targets[TwitterUserFullnames[pair.Key]].Stats.FirstRetweet = DateTime.Now; } Targets[TwitterUserFullnames[pair.Key]].Stats.Retweets++; Targets[TwitterUserFullnames[pair.Key]].Stats.LastRetweet = DateTime.Now; SaveTargets(); // Update the Birdie API and retrieve new totals. --Kris GetStats(true); // Fire event to be consumed at the app-level. --Kris RetweetEventArgs args = new RetweetEventArgs { SourceUser = pair.Key, Score = Targets[TwitterUserFullnames[pair.Key]].Stats.Retweets, OldRank = oldRank, NewRank = GetRank(TwitterUserFullnames[pair.Key]), TweetedAt = tweet.CreatedAt, RetweetedAt = DateTime.Now, Tweet = tweet.Text }; RetweetsUpdate?.Invoke(this, args); i++; if (i >= 10 || !Active || (i >= 3 && ScriptMode)) { break; } // Wait a minute between each tweet (or a second in script mode). --Kris Wait((ScriptMode ? 1000 : 60000)); if (!Active) { break; } } } if (i >= 10 || !Active || (i >= 3 && ScriptMode)) { break; } } LastCheck = DateTime.Now; } if (ScriptMode) { //Active = false; return; } Wait(60000); } }