public async Task init(String tag, DateTime start)
        {
            hashtag   = tag;
            startTime = start;

            twitter = new TwitterDataSource(tag, start);
            await twitter.init();

            // make sure we have a network connection and some data:
            if ((noNetwork = twitter.noNetwork) || (noData = twitter.noData))
            {
                return;
            }

            // start timer:
            timer = new TwitterTimer(start);

            // start clock display:
            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += dispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            dispatcherTimer.Start();

            listView.ItemsSource = twitter;

            lastRefresh = DateTime.Now;
        }
예제 #2
0
        public async Task findStartID(DateTime date)
        {
            // var lowerBound = date.ToUniversalTime().Date;
            // var upperBound = lowerBound.AddDays(1);

            var upperBound = DateTime.UtcNow.Date;
            var lowerBound = upperBound.AddDays(-1);
            var dayStart   = date.ToUniversalTime().Date;

            var httpClient = new HttpClient(new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });

            // lower bound:
            var request = new HttpRequestMessage(HttpMethod.Get, String.Format(
                                                     "https://api.twitter.com/1.1/search/tweets.json?q=a&count=1&until={0:yyyy-MM-dd}&include_entities=false", lowerBound));

            request.Headers.Add("Authorization", "Bearer " + accessToken);
            HttpResponseMessage response = await httpClient.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            var      results      = JsonConvert.DeserializeObject <TwitterSearchResults>(json);
            var      lowerBoundID = results.statuses[0].id;
            DateTime lowerDate    = DateTime.ParseExact(results.statuses[0].created_at, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);

            // upper bound:
            request = new HttpRequestMessage(HttpMethod.Get, String.Format(
                                                 "https://api.twitter.com/1.1/search/tweets.json?q=a&count=1&until={0:yyyy-MM-dd}&include_entities=false", upperBound));
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            response = await httpClient.SendAsync(request);

            json = await response.Content.ReadAsStringAsync();

            results = JsonConvert.DeserializeObject <TwitterSearchResults>(json);
            var      upperBoundID = results.statuses[0].id;
            DateTime upperDate    = DateTime.ParseExact(results.statuses[0].created_at, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);

            // calculate Tweet rate:
            long seconds = (upperDate.Ticks - lowerDate.Ticks) / 10000000;

            tweetRate = (upperBoundID - lowerBoundID) / seconds;

            // start of day:
            request = new HttpRequestMessage(HttpMethod.Get, String.Format(
                                                 "https://api.twitter.com/1.1/search/tweets.json?q=a&count=1&until={0:yyyy-MM-dd}&include_entities=false", dayStart));
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            response = await httpClient.SendAsync(request);

            json = await response.Content.ReadAsStringAsync();

            results = JsonConvert.DeserializeObject <TwitterSearchResults>(json);
            var dayStartID = results.statuses[0].id;

            long offset = Convert.ToInt64(date.ToUniversalTime().TimeOfDay.TotalSeconds);

            startID = dayStartID + (offset * tweetRate);

            // start timer:
            timer = new TwitterTimer(date);
        }