/// <summary> /// Publishes the tweets by forming the tweet message and publishing to twitter. /// </summary> private static void PublishTweetsFromFeedItems(TweetinviWrapper tweetinviWrapper, List <SyndicationItem> rssFeedItems, int startIndex) { System.Console.WriteLine($"[PublishTweetsFromFeedItems]: Publishing '{rssFeedItems.Count - startIndex}' new tweets to the timeline."); for (int i = startIndex; i < rssFeedItems.Count; i++) { string twitterMessage = GetTweetMessageFromFeedItem(rssFeedItems[i]); tweetinviWrapper.PublishTweet(twitterMessage); } }
static void Main(string[] args) { Console.WriteLine("Starting console application: 'RssFeedToTwitter'"); // Initialize the Environment Variables string consumerKey = System.Environment.GetEnvironmentVariable("RssFeedToTwitter_consumerKey"); string consumerSecret = System.Environment.GetEnvironmentVariable("RssFeedToTwitter_consumerSecret"); string userAccessToken = System.Environment.GetEnvironmentVariable("RssFeedToTwitter_userAccessToken"); string userAccessSecret = System.Environment.GetEnvironmentVariable("RssFeedToTwitter_userAccessSecret"); // Initialize the TweetinviWrapper with authentication details. TweetinviWrapper tweetinviWrapper = new TweetinviWrapper(consumerKey, consumerSecret, userAccessToken, userAccessSecret); // Initilize the program FeedToTwitterManager.Run(tweetinviWrapper); Console.WriteLine("Ending console application: 'RssFeedToTwitter'"); }
/// <summary> /// The primary logic which retrieves the feed and accordingly publishes the tweets to the twitter account. /// </summary> public static void Run(TweetinviWrapper tweetinviWrapper) { // Retrieve the feed items List <SyndicationItem> rssFeedItems = RssFeedHelpers.RetrieveRssFeedItemsInChronologicalOrder(RssFeedUrl); // Retrieve the last tweet on the timeline ITweet latestTweet = tweetinviWrapper.GetLastestTweet(); string latestTweetMessage = null; if (latestTweet != null) { latestTweetMessage = GetFeedTextFromTweetMessage(latestTweet.Text); System.Console.WriteLine($"[Run]: The lastest tweet on the timeline is '{latestTweetMessage}'."); } // Identify the position on the feed from where the tweets need to be published. // This is to ensure that the same feed item is not published as a tweet twice. int index = IdentifyFeedIndexPositionToStartPublishingTweets(rssFeedItems, latestTweetMessage); // Publish the rest of the tweets from the feed index position in chronological order. PublishTweetsFromFeedItems(tweetinviWrapper, rssFeedItems, index); }