private static async Task <ImageAnalysisResult> PerformTweetImageAnalysisIfNotAlreadyDoneAsync(string partialFileName, string link) { // Download video locally (for later use) string fileExt = link.Substring(link.Length - 3); string destinationFile = $"{partialFileName}.{fileExt}"; if (!File.Exists(destinationFile)) { await m_WebScraper.DownloadResourceAsync(link, destinationFile); } // Analyze the content pointed by link in the tweet (if not already done) Console.WriteLine($"\t\t{link}"); destinationFile = $"{partialFileName}_results.txt"; if (!File.Exists(destinationFile)) { var linkContentAnalysisResult = await m_ContentAnalyzer.AnalyzeImageFromUrlAsync(link); // Store results for later user await FileSerializer.StoreInFileAsync(linkContentAnalysisResult, destinationFile); return(linkContentAnalysisResult); } else { return(await FileSerializer.LoadFromFileAsync <ImageAnalysisResult>(destinationFile)); } }
private static async Task <VideoAnalysisResult> PerformTweetVideoAnalysisIfNotAlreadyDoneAsync(string partialFileName, string link) { var fileExt = link.Substring(link.Length - 3); string destinationFile = $"{partialFileName}.{fileExt}"; if (!File.Exists(destinationFile)) { await m_WebScraper.DownloadResourceAsync(link, destinationFile); } // Analyze video content pointed by tweet (if not already done) Console.WriteLine($"\t\t{link}"); destinationFile = $"{partialFileName}_results.txt"; if (!File.Exists(destinationFile)) { // VIDEO ANALYSIS DISABLED, TOO MUCH TIME FOR DEMO return(null); //var linkContentAnalysisResult = await m_ContentAnalyzer.AnalyzeVideoAsync(destinationFile, link); //// Store results for later user //await FileSerializer.StoreInFileAsync(linkContentAnalysisResult, destinationFile); //return linkContentAnalysisResult; } else { return(await FileSerializer.LoadFromFileAsync <VideoAnalysisResult>(destinationFile)); } }
private static async Task <IList <Tweet> > GetTweets(string[] args, string resultsPath) { // Try to load feed items from local file (if specified) string sourceFile = string.Empty; IList <Model.Tweet> tweets = null; if (args.Length == 1) { var tweetList = new List <Model.Tweet>(); var feedFiles = Directory.GetFiles(args[0], "*_tweets.txt"); foreach (var file in feedFiles) { tweetList.AddRange(await FileSerializer.LoadFromFileAsync <IList <Model.Tweet> >(file)); } tweets = tweetList; } // Retrieve recent tweets from the configured account if (tweets == null) { tweets = await m_TwitterMonitor.RetrieveTweetsAsync(); // Store tweets for later user (i.e. repeat analysis on the same content) await FileSerializer.StoreInFileAsync(tweets, $"{resultsPath}\\{DateTime.UtcNow.ToString("yyyyMMdd_HHmmss")}_tweets.txt"); } return(tweets); }
private static async Task <TextAnalysisResult> PerformTweetContentAnalysisIfNotAlreadyDoneAsync(string destinationFile, Tweet tweet) { if (!File.Exists(destinationFile)) { var contentAnalysisResult = await m_ContentAnalyzer.AnalyzeTextAsync(tweet.Content); // Store results for later user await FileSerializer.StoreInFileAsync(contentAnalysisResult, destinationFile); return(contentAnalysisResult); } else { return(await FileSerializer.LoadFromFileAsync <TextAnalysisResult>(destinationFile)); } }
private static async Task <ImageAnalysisResult> PerformImageAnalysisIfNotAlreadyDoneAsync(string partialFileName, string path) { string fileExt = path.Substring(path.Length - 3); string destinationFile = $"{partialFileName}.{fileExt}"; Console.WriteLine($"\t\t{path}"); destinationFile = $"{partialFileName}_image_results.txt"; if (!File.Exists(destinationFile)) { var imageAnalysisResult = await m_ContentAnalyzer.AnalyzeImageFromLocalFileAsync(path); // Store results for later user await FileSerializer.StoreInFileAsync(imageAnalysisResult, destinationFile); return(imageAnalysisResult); } else { return(await FileSerializer.LoadFromFileAsync <ImageAnalysisResult>(destinationFile)); } }
private static async Task <TextAnalysisResult> PerformTweetLinkContentAnalysisIfNotAlreadyDoneAsync(string fileName, string link) { string destinationFile = $"{fileName}.txt"; WebPage webPage = await FileSerializer.LoadFromFileAsync <WebPage>(destinationFile); if (webPage == null) { // Potentially, each web page may need a dedicated text extractor for optimal results // Here, for example, we have a customized extractor for TechCrunch/Mashable/Twitter pages webPage = await m_WebScraper.DownloadWebPageAsync(link); if (webPage == null) { return(null); } // Store webpage for later user await FileSerializer.StoreInFileAsync(webPage, destinationFile); } // Analyze the content pointed by link in the tweet Console.WriteLine($"\t\t{link}"); destinationFile = $"{fileName}_results.txt"; if (!File.Exists(destinationFile)) { var linkContentAnalysisResult = await m_ContentAnalyzer.AnalyzeTextAsync(webPage.Text); // Store results for later user await FileSerializer.StoreInFileAsync(linkContentAnalysisResult, destinationFile); return(linkContentAnalysisResult); } else { return(await FileSerializer.LoadFromFileAsync <TextAnalysisResult>(destinationFile)); } }