Exemplo n.º 1
0
        public async Task <TwitterResponse> PostAllNewsTweetAsync(string sortBy)
        {
            var result = await _newsData.GetAllNewsAsync(sortBy, true);

            if (result != null)
            {
                List <Article>      lstUpdated   = new List <Article>();
                LastUpdatedDateTime lastDateTime = GetUpdatedDateTime();
                DateTime            lastUpdated  = sortBy == "latest" ? DateTime.Parse(lastDateTime.LatestNewsUpdatedTime) : DateTime.Parse(lastDateTime.TopNewsUpdatedTime);

                foreach (var item in result)
                {
                    DateTime publishedDate;
                    if (!DateTime.TryParse(item.publishedAt, out publishedDate))
                    {
                        lstUpdated.Add(item);
                    }
                    else
                    {
                        if (publishedDate > lastUpdated)
                        {
                            lstUpdated.Add(item);
                        }
                    }
                }

                SetUpdatedDateTime(sortBy);
                return(await FormatFilterTweet(lstUpdated));
            }
            return(new TwitterResponse());
        }
Exemplo n.º 2
0
        public void SetUpdatedDateTime(string mode)
        {
            DateTime current = DateTime.UtcNow;

            current = current.AddHours(-8);

            LastUpdatedDateTime lastDateTime = GetUpdatedDateTime();

            if (mode == "latest")
            {
                lastDateTime.LatestNewsUpdatedTime = lastDateTime.LastTweetUpdatedTime = current.ToString();
            }
            else if (mode == "top")
            {
                lastDateTime.TopNewsUpdatedTime = lastDateTime.LastTweetUpdatedTime = current.ToString();
            }
            else
            {
                lastDateTime.LastTweetUpdatedTime = current.ToString();
            }

            string output = JsonConvert.SerializeObject(lastDateTime, Formatting.Indented);

            File.WriteAllText("lastUpdatedDateTime.json", output);
        }
Exemplo n.º 3
0
        public IList <string> GetLastUpdatedDateTime()
        {
            var    lastUpdateTime            = new List <string>();
            string fileData                  = System.IO.File.ReadAllText("lastUpdatedDateTime.json");
            LastUpdatedDateTime lastDateTime = JsonConvert.DeserializeObject <LastUpdatedDateTime>(fileData);

            lastUpdateTime.Add(lastDateTime.LastTweetUpdatedTime);
            lastUpdateTime.Add(lastDateTime.LatestNewsUpdatedTime);
            lastUpdateTime.Add(lastDateTime.TopNewsUpdatedTime);
            return(lastUpdateTime);
        }