private void ListenerThreadFunction() { TwitterCredentials.SetCredentials( ConfigurationManager.AppSettings["token_AccessToken"], ConfigurationManager.AppSettings["token_AccessTokenSecret"], ConfigurationManager.AppSettings["token_ConsumerKey"], ConfigurationManager.AppSettings["token_ConsumerSecret"]); while (threadRunning) { try { //var hbase = new HBaseWriter(); stream = Stream.CreateFilteredStream(); var location = Geo.GenerateLocation(-180, -90, 180, 90); stream.AddLocation(location); var tweetCount = 0; var timer = Stopwatch.StartNew(); stream.MatchingTweetReceived += (sender, args) => { tweetCount++; var tweet = args.Tweet; // Store indexItem in the buffer lock (queue) { queue.Enqueue(tweet); } if (timer.ElapsedMilliseconds > 1000) { if (tweet.Coordinates != null) { Context.Logger.Info("{0}: {1} {2}", tweet.Id, tweet.Language.ToString(), tweet.Text); Context.Logger.Info("\tLocation: {0}, {1}", tweet.Coordinates.Longitude, tweet.Coordinates.Latitude); } timer.Restart(); Context.Logger.Info("===== Tweets/sec: {0} =====", tweetCount); tweetCount = 0; } }; stream.StartStreamMatchingAllConditions(); } catch (Exception ex) { Context.Logger.Fatal("Exception: {0}", ex.Message); } } }
private static void Stream_FilteredStreamExample() { for (; ;) { try { var hbase = new HBaseWriter(); var stream = Stream.CreateFilteredStream(); var location = Geo.GenerateLocation(-180, -90, 180, 90); stream.AddLocation(location); var tweetCount = 0; var timer = Stopwatch.StartNew(); stream.MatchingTweetReceived += (sender, args) => { tweetCount++; var tweet = args.Tweet; hbase.WriteTweet(tweet); if (timer.ElapsedMilliseconds > 1000) { if (tweet.Coordinates != null) { Console.WriteLine("{0}: {1} {2}", tweet.Id, tweet.Language.ToString(), tweet.Text); Console.WriteLine("\tLocation: {0}, {1}", tweet.Coordinates.Longitude, tweet.Coordinates.Latitude); } timer.Restart(); Console.WriteLine("===== Tweets/sec: {0} =====", tweetCount); tweetCount = 0; } /*IEnumerable<ILocation> matchingLocations = args.Tweet.; * foreach (var matchingLocation in matchingLocations) * { * Console.Write("({0}, {1}) ;", matchingLocation.Coordinate1.Latitude, matchingLocation.Coordinate1.Longitude); * Console.WriteLine("({0}, {1})", matchingLocation.Coordinate2.Latitude, matchingLocation.Coordinate2.Longitude); * }*/ }; stream.StartStreamMatchingAllConditions(); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } } }
private static void Stream_FilteredStreamExample() { for (; ;) { try { HBaseWriter hbase = new HBaseWriter(); var stream = Stream.CreateFilteredStream(); stream.AddLocation(Geo.GenerateLocation(-180, -90, 180, 90)); var tweetCount = 0; var timer = Stopwatch.StartNew(); stream.MatchingTweetReceived += (sender, args) => { tweetCount++; var tweet = args.Tweet; // Write Tweets to HBase hbase.WriteTweet(tweet); if (timer.ElapsedMilliseconds > 1000) { if (tweet.Coordinates != null) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n{0}: {1} {2}", tweet.Id, tweet.Language.ToString(), tweet.Text); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\tLocation: {0}, {1}", tweet.Coordinates.Longitude, tweet.Coordinates.Latitude); } timer.Restart(); Console.WriteLine("\tTweets/sec: {0}", tweetCount); tweetCount = 0; } }; stream.StartStreamMatchingAllConditions(); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } } }
private static void Stream_FilteredStreamExample() { for (; ;) { try { var clients = GlobalHost.ConnectionManager.GetHubContext <TwitterHub>().Clients; var globalStreamGroupName = "Global"; var stream = Stream.CreateFilteredStream(); //stream.AddTrack("lol"); //test purpose //stream.AddTrack("me"); stream.AddLocation(Geo.GenerateLocation(-180, -90, 180, 90)); var tweetCount = 0; var timer = Stopwatch.StartNew(); stream.MatchingTweetReceived += (sender, args) => { tweetCount++; var tweet = args.Tweet; if (timer.ElapsedMilliseconds > 1000) { if (tweet.Coordinates != null) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n{0}: {1} {2}", tweet.Id, tweet.Language.ToString(), tweet.Text); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\tLocation: {0}, {1}", tweet.Coordinates.Longitude, tweet.Coordinates.Latitude); } timer.Restart(); Console.WriteLine("\tTweets/sec: {0}", tweetCount); tweetCount = 0; } var tweetText = tweet.Text; var userScreenName = tweet.Creator.ScreenName; // tweetJToken["user"]["screen_name"].ToString(); var imageUrl = tweet.Creator.ProfileImageUrlHttps; //tweetJToken["user"]["profile_image_url_https"].ToString(); var tweetModel = new Kirnau.Social.Twitter.Adapter.Model.Tweet() { TweetText = tweetText, User = userScreenName, ImageUrl = imageUrl }; if (tweet.Coordinates != null) { tweetModel.Longitude = tweet.Coordinates.Longitude.ToString(); tweetModel.Latitude = tweet.Coordinates.Latitude.ToString(); } ////broadcast tweet to global stream subscribers clients.Group(globalStreamGroupName).broadcastTweet(tweetModel); string tweetHashTag = string.Empty; if (tweet.Hashtags != null) { foreach (var tag in tweet.Hashtags) { tweetHashTag += tag.Text + ","; } } if (tweetHashTag == "") { tweetHashTag = "none"; } else { tweetHashTag = tweetHashTag.Remove(tweetHashTag.Length - 2); } PostTweetToClient(tweetText, tweetHashTag); }; stream.StartStreamMatchingAllConditions(); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } } }