public static void Main(string[] args) { //LogObserver logObserver = new LogObserver(); try { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Where(tweet => tweet.Topic != "Unknown").Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore, PlaceTimeZone = tweet.TimeZone, TweetText = tweet.Text, Retweeted = tweet.Retweeted, RetweetCount = tweet.RetweetCount }); datum.ToObservable().Subscribe(myEventHubObserver); } catch (Exception ex) { System.IO.File.AppendAllText(@"F:\www.txt", ex.Message.ToString() + " kkk " + ex.InnerException.ToString() + " sdfsd " + ex.StackTrace.ToString()); // ex.Data.ToObservable<string>().Subscribe(logObserver); } }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; var accountKey = ConfigurationManager.AppSettings["accountkey"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); //Call the Twitter Stream API var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = Convert.ToDateTime(tweet.CreatedAt), Topic = keywords, Text = tweet.Text }); //Send data to event hub datum.ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { ReadConfig(); //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var thread = new Thread(new ThreadStart(Program.DoHeartbeat)); thread.Start(); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)) .Select(tweet => Sentiment.ComputeScore(tweet)) .Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, UtcOffset = tweet.UtcOffset, UserName = tweet.UserName, SentimentScore = tweet.SentimentScore }); datum.ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); try { var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore, Text = tweet.Text, Location = tweet.Location, sentiment = tweet.Sentiment, ProfileImageUrl = tweet.ProfileImageUrl, hashtags = tweet.hashtag }); datum.ToObservable().Subscribe(myEventHubObserver); } catch { } }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var searchGroups = ConfigurationManager.AppSettings["twitter_keywords"]; var removeAllUndefined = !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["clear_all_with_undefined_sentiment"]) ? Convert.ToBoolean(ConfigurationManager.AppSettings["clear_all_with_undefined_sentiment"]) : false; var sendExtendedInformation = !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["send_extended_information"]) ? Convert.ToBoolean(ConfigurationManager.AppSettings["send_extended_information"]) : false; var AzureOn = !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["AzureOn"]) ? Convert.ToBoolean(ConfigurationManager.AppSettings["AzureOn"]) : false; var mode = ConfigurationManager.AppSettings["match_mode"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config, AzureOn); var keywords = searchGroups.Contains('|') ? string.Join(",", searchGroups.Split('|')) : searchGroups; var tweet = new Tweet(); var datum = tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords, searchGroups)).Where(e => !string.IsNullOrWhiteSpace(e.Text)).Select(t => Sentiment.ComputeScore(t, searchGroups, mode)).Select(t => new Payload { CreatedAt = t.CreatedAt, Topic = t.Topic, SentimentScore = t.SentimentScore, Author = t.UserName, Text = t.Text, SendExtended = sendExtendedInformation }); if (removeAllUndefined) { datum = datum.Where(e => e.SentimentScore > -1); } datum.Where(e => e.Topic != "No Match").ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)). Select(tweet => TwitterParser.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic }); datum.ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { var appSettings = ConfigurationManager.AppSettings; //Configure Twitter OAuth var oauthToken = appSettings["oauth_token"]; var oauthTokenSecret = appSettings["oauth_token_secret"]; var oauthCustomerKey = appSettings["oauth_consumer_key"]; var oauthConsumerSecret = appSettings["oauth_consumer_secret"]; var searchGroups = appSettings["twitter_keywords"]; var removeAllUndefined = !string.IsNullOrWhiteSpace(appSettings["clear_all_with_undefined_sentiment"]) ? Convert.ToBoolean(appSettings["clear_all_with_undefined_sentiment"]) : false; var sendExtendedInformation = !string.IsNullOrWhiteSpace(appSettings["send_extended_information"]) ? Convert.ToBoolean(appSettings["send_extended_information"]) : false; var AzureOn = !string.IsNullOrWhiteSpace(appSettings["AzureOn"]) ? Convert.ToBoolean(appSettings["AzureOn"]) : false; var mode = appSettings["match_mode"]; var createBigFile = !string.IsNullOrWhiteSpace(appSettings["create_big_file"]) ? Convert.ToBoolean(appSettings["create_big_file"]) : false; long fileSizeLimit = !string.IsNullOrWhiteSpace(appSettings["filesizelimit"]) ? Convert.ToInt64(appSettings["filesizelimit"]) : defaultFileSizeLimit; if (fileSizeLimit < minFileSizeLimit) { fileSizeLimit = minFileSizeLimit; Console.WriteLine("File size limit in config was too small and has been set to {0:N0}", fileSizeLimit); } var includeRetweets = !string.IsNullOrWhiteSpace(appSettings["IncludeRetweets"]) ? Convert.ToBoolean(appSettings["IncludeRetweets"]) : false; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = appSettings["EventHubConnectionString"]; config.EventHubName = appSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config, AzureOn); var keywords = searchGroups.Contains('|') ? string.Join(",", searchGroups.Split('|')) : searchGroups; var tweet = new Tweet(); Console.WriteLine("Searching Tweets for keywords: {0}", keywords); var folderName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"tweets\"); EnsureDirectory(folderName); var twitterConfig = new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords, searchGroups, createBigFile, folderName, includeRetweets, fileSizeLimit); // Write out the config especially the keywords... (can only happen AFTER TwitterConfig has been created! string path = Path.Combine(folderName, Path.ChangeExtension(twitterConfig.BigFileName, ".config")); File.WriteAllText(path, @"CAS BDA Search (Team Pharma) for Tweets was started with the following keywords:" + Environment.NewLine + Environment.NewLine + keywords, Encoding.UTF8); // test foreach (var sendingPayload in tweet.StreamStatuses(twitterConfig)) { } // end test //**var sendingPayload = tweet.StreamStatuses(twitterConfig).Where(e => !string.IsNullOrWhiteSpace(e.Text)).Select(t => Sentiment.ComputeScore(t, searchGroups, mode)).Select(t => new Payload { CreatedAt = t.CreatedAt, Topic = t.Topic, SentimentScore = t.SentimentScore, Author = t.UserName, Text = t.Text, SendExtended = sendExtendedInformation, Language = t.Language}); //if (removeAllUndefined) //{ // sendingPayload = sendingPayload.Where(e => e.SentimentScore > -1); //} //sendingPayload.Where(e => e.Topic != "No Match").ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { /* Get hashtag phrase that will be listened to / analysed by the Text Analytics API from user input. Basic use is to ask user: * Which hashtag do you want to listen to? * Which Event Hub do you want to send the sentiment score to? */ //string hashtag = "microsoft"; //string eventhubName = ""; //string eventhubConn = ""; //Console.WriteLine("Enter hashtag phrase (without the #): "); //hashtag = Console.ReadLine(); //ConfigurationManager.AppSettings["twitter_keywords"] = hashtag; //Console.WriteLine("Enter Event Hub Name: "); //eventhubName = Console.ReadLine(); //Console.WriteLine("Enter Event Hub Connection String: "); //eventhubConn = Console.ReadLine(); //var config = new EventHubConfig(); //config.ConnectionString = eventhubConn; //config.EventHubName = eventhubName; //var myEventHubObserver = new EventHubObserver(config); //Console.WriteLine("START\n"); //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; var accountKey = ConfigurationManager.AppSettings["accountkey"]; //Configure EventHub (comment this out if using user input code above) var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); //Azure ML Service string ServiceBaseUri = "https://api.datamarket.azure.com/"; var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(ServiceBaseUri); string creds = "AccountKey:" + accountKey; string authorizationHeader = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(creds)); httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Original Sentiment demo code var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = Convert.ToDateTime(tweet.CreatedAt), Topic = tweet.Topic, SentimentScore = SentimentValue(tweet.Text, httpClient), Text = tweet.Text }); datum.ToObservable().Subscribe(myEventHubObserver); }