public void GetRateLimits(string mess) { var rateLimits = RateLimit.GetCurrentCredentialsRateLimits(); if (rateLimits != null) { try { var currentUser = User.GetLoggedUser().Name; FOutputStatus[0] = "F**k YEAH! Logged in as " + currentUser; FLogger.Log(LogType.Debug, "F**k YEAH! Logged in as " + currentUser); FOutputSearchesRemaining[0] = rateLimits.SearchTweetsLimit.Limit; FOutputSearchesReset[0] = rateLimits.SearchTweetsLimit.ResetDateTime.ToString(); FOutputStatusBool[0] = true; loggedIn = true; } catch { FOutputStatus[0] = mess; FLogger.Log(LogType.Debug, mess); ClearOutputPins(); FOutputStatusBool[0] = false; loggedIn = false; } } else { FOutputStatus[0] = mess; FLogger.Log(LogType.Debug, mess); ClearOutputPins(); FOutputStatusBool[0] = false; loggedIn = false; } }
public static void GetCurrentCredentialsRateLimits() { var tokenRateLimits = RateLimit.GetCurrentCredentialsRateLimits(); Console.WriteLine("Remaning Requests for GetRate : {0}", tokenRateLimits.ApplicationRateLimitStatusLimit.Remaining); Console.WriteLine("Total Requests Allowed for GetRate : {0}", tokenRateLimits.ApplicationRateLimitStatusLimit.Limit); Console.WriteLine("GetRate limits will reset at : {0} local time", tokenRateLimits.ApplicationRateLimitStatusLimit.ResetDateTime.ToString("T")); }
public void Evaluate(int SpreadMax) { //FLastSearchStatus[0]=lastSearchStatus; if (FLogin[0]) { /*try * {*/ if (!CheckForInternetConnection()) { FOutputStatus[0] = "Internet is f****d bro."; } else { //TwitterCredentials.SetCredentials(accToken, accSecret, consKey, consSecret); TwitterCredentials.SetCredentials(FCredentials[0], FCredentials[1], FCredentials[2], FCredentials[3]); var rateLimits = RateLimit.GetCurrentCredentialsRateLimits(); if (rateLimits != null) { FOutputStatus[0] = "F**k YEAH!/n Search Limit: " + rateLimits.SearchTweetsLimit.Limit.ToString() + " Search Remaining: " + rateLimits.SearchTweetsLimit.Remaining.ToString() + "/n FavoritesListLimit: " + rateLimits.FavoritesListLimit.Limit.ToString() + " Search Remaining: " + rateLimits.FavoritesListLimit.Remaining.ToString(); limitSearchRemaining = rateLimits.SearchTweetsLimit.Limit; limitResetTime = rateLimits.SearchTweetsLimit.ResetDateTime.ToString(); loggedIn = true; } else { FOutputStatus[0] = "Nope! Bad credentials."; loggedIn = false; } } // } /*catch (System.ArgumentNullException e) * { * lastSearchStatus = "Internet connection is f****d bro"; * throw new System.ArgumentNullException("Internet connection is f****d bro", e); * }*/ } }
internal static async Task PeriodicTwitterAsync(TimeSpan interval, TwitterFeed twitterFeed) { while (true) { var sbOut = new StringBuilder(); sbOut.Append($"\n{DateTime.Now}\nTwitter Feed Reader."); Auth.SetUserCredentials(twitterFeed.ConsumerKey, twitterFeed.ConsumerSecret, twitterFeed.AccessToken, twitterFeed.AccessTokenSecret); var authenticatedUser = User.GetAuthenticatedUser(); sbOut.Append($"\nAuthenticated Twitter User: {authenticatedUser}"); if (twitterFeed.Searches.Any()) { foreach (var s in twitterFeed.Searches) { var procCount = 0; sbOut.Append($"\nProcessing Search: {s.SearchTerm}"); var searchParameter = new SearchTweetsParameters(s.SearchTerm) { SearchType = SearchResultType.Mixed, MaximumNumberOfResults = 100, SinceId = s.LastProcessedId }; var tweets = Search.SearchTweets(searchParameter); var rateLimits = RateLimit.GetCurrentCredentialsRateLimits(); sbOut.Append($"\nRate Limit info: {rateLimits.SearchTweetsLimit}"); foreach (var t in tweets.OrderBy(x => x.Id)) { var message = new MattermostMessage { Channel = s.BotChannelOverride == ""?null:s.BotChannelOverride, Username = s.BotNameOverride == ""? null:s.BotNameOverride, IconUrl = s.BotImageOverride == "" ? null : new Uri(s.BotImageOverride), Attachments = new List <MattermostAttachment> { new MattermostAttachment { Pretext = $"Tweet by [@{t.CreatedBy.ScreenName}](https://twitter.com/{t.CreatedBy.ScreenName}) at [{t.CreatedAt:HH:mm d MMM yyyy} UTC]({t.Url})", Text = $">{t.FullText}", AuthorName = t.CreatedBy.Name ?? "", AuthorLink = new Uri($"https://twitter.com/{t.CreatedBy.ScreenName}"), AuthorIcon = new Uri(t.CreatedBy.ProfileImageUrl400x400 ?? "") } } }; try { await Program.PostToMattermost(message); s.LastProcessedId = t.Id; procCount++; } catch (Exception e) { sbOut.Append($"\nException: {e.Message}"); } } sbOut.Append($"\nProcessed {procCount}/{tweets.Count()} tweets"); } } Console.WriteLine(sbOut.ToString()); Program.SaveConfigSection(twitterFeed); await Task.Delay(interval).ConfigureAwait(false); } }