Пример #1
0
        public void JsonToModelConverterTest()
        {
            string json    = "{\"data\":{\"text\":\"RT @ohmypinks: jisoo best girl vote #HowYouLikeThat for #BestMusic…\",\"entities\":{\"mentions\":[{\"start\":3,\"end\":13,\"username\":\"ohmypinks\"}],\"hashtags\":[{\"start\":109,\"end\":124,\"tag\":\"HowYouLikeThat\"}]},\"id\":\"1386181858203930624\",\"created_at\":\"2021-04-25T04:54:43.000Z\"}}";
            var    service = new SampledStreamService(new MemoryStore <SampledStreamModel>());
            var    result  = service.JsonToModelConverter(json);

            Assert.AreEqual(result.HashTags.Count, 1, "Json is converted to .Net object");
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public void Initialize()
        {
            //Initialize service
            var service = new SampledStreamService(new MemoryStore <SampledStreamModel>());

            //Initialize view and VM and Inject the view to UI
            var sampledStreamView      = new SampledStreamView();
            var sampledStreamViewModel = new SampledStreamViewModel(service);

            sampledStreamView.DataContext = sampledStreamViewModel;
            _mainWindowViewModel.InjectViewInContainer(sampledStreamView);
        }
Пример #3
0
        public async Task StartStreaming(int sampleSize)
        {
            Log.Information($"TwitterStreamService.StartStreaming {DateTime.Now:hh:mm:ss}");
            await cache.ResetCache(sampleSize);

            try
            {
                SampledStreamService streamService = new SampledStreamService(oAuthInfo, this.appSettings.BearerToken);
                streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
                streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=author_id,attachments.media_keys&tweet.fields=public_metrics,attachments,context_annotations,entities&media.fields=duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics", sampleSize, 1);
            }
            catch (Exception)
            {
                throw;
            }
        }
        static void Main(string[] args)
        {
            /*TwitinfoModel ti = new TwitinfoModel
             * {
             *  TwitJson = "sample twitter info"
             * };*/

            //List<SampledStream> lstSampledStream = new List<SampledStream>();
            string _ConsumerKey       = ConfigurationManager.AppSettings.Get("ConsumerKey");
            string _ConsumerSecret    = ConfigurationManager.AppSettings.Get("ConsumerSecret");
            string _AccessToken       = ConfigurationManager.AppSettings.Get("AccessToken");
            string _AccessTokenSecret = ConfigurationManager.AppSettings.Get("AccessTokenSecret");
            string _BearerToken       = ConfigurationManager.AppSettings.Get("BearerToken");

            //// Connect to emitter
            //var emitter = Connection.Establish();

            // Set up your credentials
            OAuthInfo oAuthInfo = new OAuthInfo
            {
                AccessSecret   = _AccessTokenSecret,
                AccessToken    = _AccessToken,
                ConsumerSecret = _ConsumerSecret,
                ConsumerKey    = _ConsumerKey,
                BearerToken    = _BearerToken
            };


            // Sampled Stream Service Test
            SampledStreamService streamService = new SampledStreamService(oAuthInfo);

            streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
            streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id", 100, 5);

            //streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream", 100, 1);

            //Console.WriteLine("Twitter Analytics");
            /*Console.WriteLine($"{ ti.TwitJson }");*/
        }
Пример #5
0
        public void StoreAndRetriveData()
        {
            string domain  = "twitter.com";
            var    service = new SampledStreamService(new MemoryStore <SampledStreamModel>());

            //store
            var sampledStreamModel = new SampledStreamModel()
            {
                HasEmoji = false, HasPhotoUrl = false, UrlDomain = new List <string> {
                    domain
                }
            };
            var storeResult = service.StoreModel(sampledStreamModel);

            Assert.AreEqual(storeResult, true);

            //Retrive
            var retriveResult = service.RetriveModel().GetAwaiter().GetResult();

            Assert.IsNotNull(retriveResult);
            Assert.AreEqual(retriveResult.Item1, 1);
            Assert.AreEqual(retriveResult.Item2.Count, 1);
        }
        static void Main(string[] args)
        {
            string _ConsumerKey       = ConfigurationManager.AppSettings.Get("ConsumerKey");
            string _ConsumerSecret    = ConfigurationManager.AppSettings.Get("ConsumerSecret");
            string _AccessToken       = ConfigurationManager.AppSettings.Get("AccessToken");
            string _AccessTokenSecret = ConfigurationManager.AppSettings.Get("AccessTokenSecret");

            OAuthInfo oAuthInfo = new OAuthInfo
            {
                AccessSecret   = _AccessTokenSecret,
                AccessToken    = _AccessToken,
                ConsumerSecret = _ConsumerSecret,
                ConsumerKey    = _ConsumerKey
            };

            HideReplyService hideRepliesService = new HideReplyService(oAuthInfo);
            HideReplyModel   model = hideRepliesService.HideReply("1296341968176451585");

            // Sampled Stream Service Test
            SampledStreamService streamService = new SampledStreamService(oAuthInfo);

            streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
            streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id", 100, 5);

            // Recent Search
            RecentSearchService searchService = new RecentSearchService(oAuthInfo);

            List <RecentSearchResultsModel> resultsModels = searchService.SearchTweets("iphone", 100, 3);

            // Tweet(s)
            TweetService tweetsService = new TweetService(oAuthInfo);
            TweetModel   tweetModel    = tweetsService.GetTweet("1293779846691270658");

            List <string> tids = new List <string>();

            tids.Add("1293779846691270658"); // social opinion tweet
            tids.Add("1293779846691270658"); // social opinion tweet
            TweetsModel tweetModels = tweetsService.GetTweets(tids);

            // User(s)
            UserService userService = new UserService(oAuthInfo);
            UserModel   userModel   = userService.GetUser("socialopinions");

            List <string> users = new List <string>();

            users.Add("jamie_maguire1");
            users.Add("socialopinions");
            UsersModel usersResults = userService.GetUsers(users);

            // Metrics
            List <string> ids = new List <string>();

            ids.Add("1258736674844094465"); // social opinion tweet
            TweetMetricsService     service      = new TweetMetricsService(oAuthInfo);
            List <TweetMetricModel> metricModels = service.GetTweetMetrics(ids);

            // testing Filtered Stream
            FilteredStreamService filteredStreamService = new FilteredStreamService(oAuthInfo);

            List <FilteredStreamRule> rules = filteredStreamService.CreateRule(
                new MatchingRule {
                tag = "testing #iPhone", Value = "#iphone"
            });

            filteredStreamService.DataReceivedEvent += FilteredStreamService_DataReceivedEvent;
            filteredStreamService.StartStream("https://api.twitter.com/2/tweets/search/stream?tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,source,text,withheld&expansions=author_id&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld", 10, 5);
        }
Пример #7
0
 public SampledStreamViewModel(SampledStreamService service) : base(service)
 {
     SampledStreamServiceInst = service;
     DateTimeStreamingStarted = SampledStreamServiceInst.StartSampledStream();
     StartTimerToFetchAndDisplayData();
 }