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); }
public static TwitterPayload ComputeScore(Tweet tweet, string twitterKeywords) { return(new TwitterPayload { ID = tweet.Id, CreatedAt = Sentiment.ParseTwitterDateTime(tweet.CreatedAt), UserName = tweet.User != null ? tweet.User.Name : null, TimeZone = tweet.User != null ? (tweet.User.TimeZone != null ? tweet.User.TimeZone : "(unknown)") : "(unknown)", ProfileImageUrl = tweet.User != null ? (tweet.User.ProfileImageUrl != null ? tweet.User.ProfileImageUrl : "(unknown)") : "(unknown)", Text = tweet.Text, Retweeted = tweet.Retweeted, RetweetCount = tweet.RetweetCount, Language = tweet.Language != null ? tweet.Language : "(unknown)", RawJson = tweet.RawJson, SentimentScore = (int)Sentiment.Analyze(tweet.Text), Topic = Sentiment.DetermineTopic(tweet.Text, twitterKeywords), }); }
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); }
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"]; //Configure EventHub var config = new LogicAppConfig(); config.LogicAppURL = ConfigurationManager.AppSettings["LogicAppURL"]; var myLogicAppObserver = new LogicAppObserver(config); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)); datum.ToObservable().Subscribe(myLogicAppObserver); }
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 => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore, Text = tweet.Text, HasSymbol = tweet.HasSymbol, UserName = tweet.UserName }); 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 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 myTargetObserver = new EventHubObserver(config, AzureOn); var kafkaConfig = new ProducerConfig { BootstrapServers = "pfwstreaming.westeurope.cloudapp.azure.com:9092", //BootstrapServers = "13.81.68.193:9092", ClientId = Dns.GetHostName() }; //kafkaConfig.SaslUsername = "******"; //kafkaConfig.SaslPassword = "******"; kafkaConfig.SecurityProtocol = SecurityProtocol.Plaintext; //kafkaConfig.SaslMechanism = SaslMechanism.Plain; //kafkaConfig. //kafkaConfig. //kafkaConfig.SaslMechanism = SaslMechanism.Plain; var myTargetObserver = new KafkaObserver(kafkaConfig, 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 { ID = t.ID, CreatedAt = t.CreatedAt, Topic = t.Topic, SentimentScore = t.SentimentScore, Author = t.UserName, Text = t.Text, SendExtended = sendExtendedInformation, Language = t.Language, TimeZone = t.TimeZone }); if (removeAllUndefined) { datum = datum.Where(e => e.SentimentScore > -1); } datum.Where(e => e.Topic != "No Match").ToObservable().Subscribe(myTargetObserver); }
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) { /* 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); }