Пример #1
0
        public static void Start( )
        {
            stream = Tweetinvi.Stream.CreateFilteredStream( );

            stream.FilterLevel = FilterLevel;

            stream.MatchingTweetReceived        += OnTweetReceived;
            stream.WarningFallingBehindDetected += WarningFallingBehind;
            stream.DisconnectMessageReceived    += DisconnectedMessageReceived;

            foreach (string keyword in Keywords)
            {
                stream.AddTrack(keyword);
            }
            foreach (string language in Languages)
            {
                stream.AddTweetLanguageFilter(language);
            }
            foreach (Coordinates coord in Coords)
            {
                stream.AddLocation(coord, new Coordinates(coord.Latitude + 1.0, coord.Longitude + 1.0));
            }

            TweetCount = 0;

            RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;
            Task streamAsync = Sync.ExecuteTaskAsync(() => stream.StartStreamMatchingAllConditionsAsync( ));
        }
Пример #2
0
 public void Dispose()
 {
     if (_filteredStream != null)
     {
         _filteredStream.StreamStarted         -= OnStreamStarted;
         _filteredStream.MatchingTweetReceived -= OnMatchingTweetReceived;
         _filteredStream.StopStream();
         _filteredStream = null;
     }
 }
Пример #3
0
 public void Dispose()
 {
     if (_filteredStream != null)
     {
         streamWorker.CancelAsync();
         _filteredStream.MatchingTweetReceived -= OnMatchingTweetReceived;
         _filteredStream.StopStream();
         _filteredStream = null;
     }
 }
        public JsonResult StartStream(string[] list)
        {
            try
            {
                var keyword = list[0];
                var path    = list[1];
                //var iterations = 100000;
                path = path + "\\" + "API_" + keyword + "_" + string.Format("{0:yyyy-MM-dd_hh-mm-ss-fff}", DateTime.Now) + ".txt";

                object lock1 = new Object();

                lock (lock1)
                {
                    if (!System.IO.File.Exists(path))
                    {
                        System.IO.File.Create(path);
                    }
                }
                try{
                    if (t != null)
                    {
                        stream.StopStream();
                    }
                } catch (Exception e) {
                    return(new JsonResult(new { success = true, responseText = "Failed to abort old thread" }));
                }
                this.t = new Thread(() =>
                {
                    this.stream = Tweetinvi.Stream.CreateFilteredStream();
                    if (keyword != "")
                    {
                        stream.AddTrack(keyword);
                    }

                    stream.MatchingTweetReceived += (sender, args) =>
                    {
                        System.IO.File.AppendAllText(path, args.Json + "\n");
                        Console.WriteLine(args.Tweet);
                    };
                    stream.StartStreamMatchingAllConditions();
                    Console.WriteLine("Stream started");
                    //stream.StopStream();
                });
                lock (lock1)
                {
                    t.Start();
                }
                return(new JsonResult(new { success = true, responseText = "Started stream for keyword" + keyword + ". Saving to file at location " + path + "." }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, responseText = "Exceptions occured while attempting to open stream." }));
            }
        }
        private void StartStreaming()
        {
            if (!TwitterAuthenticated)
            {
                return;
            }

            List <String> FilterStrings = Settings.GetValueFromConfig("Stream_FilterTrack").Split(',').ToList();

            Filteredstream = Stream.CreateFilteredStream();

            foreach (String filter in FilterStrings)
            {
                Filteredstream.AddTrack(filter);
            }

            Console.WriteLine("Filter tracks: " + String.Join("||", FilterStrings));

            Filteredstream.MatchingTweetReceived += (sender2, args) =>
            {
                ITweet tw = args.Tweet;
                ProcessTweet(tw);
            };

            Filteredstream.StreamStarted += (sender2, args) =>
            {
                Console.WriteLine("Stream started");

                timer.Enabled = true;
                Task.Factory.StartNew(() => { GCS_SaveInNewThread(); });
            };

            Filteredstream.StreamStopped += (sender2, args) =>
            {
                Console.WriteLine(args.Exception);
                Console.WriteLine(args.DisconnectMessage);

                timer.Stop();
                timer.Enabled = false;

                Console.WriteLine("Restarting in 5 Second");
                Thread.Sleep(5000);
                RestartStream();
            };

            timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
            timer.Interval = 10000;

            RestartStream();
        }
        public TwitterStream(Event ev, string ConsumerKey, string ConsumerSecret, string AccessToken, string AccessTokenSecret)
        {
            this.streamEvent       = ev;
            this.ConsumerKey       = ConsumerKey;
            this.ConsumerSecret    = ConsumerSecret;
            this.AccessToken       = AccessToken;
            this.AccessTokenSecret = AccessTokenSecret;
            UpdateCredentials();
            stream = Stream.CreateFilteredStream();

            this.displayedTweets = _tweetRepo.GetLatest(tweetsLimit, streamEvent.Name).ToList();

            updateTimer = new Timer(new TimerCallback(MaintainTweets), null, 0, UPDATE_INTERVAL);
        }
Пример #7
0
 public void StartMonitoring(string query, EventHandler <Tweetinvi.Events.MatchedTweetReceivedEventArgs> callback)
 {
     try {
         tweetStream = Stream.CreateFilteredStream();
         tweetStream.AddTrack(query);
         tweetStream.MatchingTweetReceived += callback;
         tweetStream.StartStreamMatchingAllConditions();
         status = 0;
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Error starting Twitter monitoring: " + ex.Message);
         status = -1;
     }
 }
Пример #8
0
 public void StartStream()
 {
     if (_filteredStream == null)
     {
         // For Reply
         _filteredStream = Tweetinvi.Stream.CreateFilteredStream();
         _filteredStream.AddTrack("@" + _botUser.ScreenName);
         _filteredStream.MatchingTweetReceived += OnMatchingTweetReceived;
         streamWorker.RunWorkerAsync();
         logger.LogInformation("Twitter stream start");
     }
     else
     {
         logger.LogWarning("Twitter stream already started");
     }
 }
Пример #9
0
 public void StartStream()
 {
     if (_filteredStream == null)
     {
         // For Reply
         _filteredStream = Tweetinvi.Stream.CreateFilteredStream();
         _filteredStream.AddTrack("@" + _botUser.ScreenName);
         _filteredStream.StreamStarted         += OnStreamStarted;
         _filteredStream.MatchingTweetReceived += OnMatchingTweetReceived;
         // TODO これに限らず例外処理と継続は見ておく
         _filteredStream.StartStreamMatchingAllConditionsAsync();
     }
     else
     {
         Debug.WriteLine("Twitter stream already started");
     }
 }
Пример #10
0
        public void SetupStream()
        {
            SetupDb();
            tweetParser = new TweetParser();
            TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
            Auth.SetUserCredentials(_consumerKey, _consumerSecret, _accessToken, _accessTokenSecret);
            stream = Stream.CreateFilteredStream();
            stream.AddTrack(query);

            stream.MatchingTweetReceived += (sender, args) =>
            {
                tweetsList.Add(args.Tweet);
                var tweet          = args.Tweet;
                var matchingTracks = args.MatchingTracks;
                var matchedOn      = args.MatchOn;
                Debug.WriteLine(args.Tweet);
            };

            Models.TweetCount counter = new Models.TweetCount();
            counter.Key   = COUNTERKEY;
            counter.Count = 0;
            tweetCounterCollection.InsertOne(counter);
        }
Пример #11
0
        public TweetHub()
        {
            var cred = Auth.SetUserCredentials("", "", "", "");

            stream = Stream.CreateFilteredStream();
        }