Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.ServiceModel.Syndication;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace WebApp.Modules
- {
- class ReadFeeds
- {
- private Requests requests = new Requests();
- private List<string> LoadRssFeed()
- {
- List<string> rssFeedUrlList = new List<string>();
- var mainPage = requests.HtmlLoad("https://vnexpress.net/rss");
- foreach(var item in mainPage.DocumentNode.SelectNodes("/html/body/section[4]/div/div/ul/li"))
- {
- rssFeedUrlList.Add(item.SelectSingleNode("a").Attributes["href"].Value);
- }
- return rssFeedUrlList;
- }
- public Dictionary<string, string> GetCovid19Info()
- {
- string data = requests.Get("https://api.covid19api.com/summary");
- var json = JObject.Parse(data);
- Dictionary<string, string> covid19Info = new Dictionary<string, string>();
- covid19Info.Add("WorldTotalRecovered", json["Global"]["TotalRecovered"].ToString());
- covid19Info.Add("WorldTotalConfirmed", json["Global"]["TotalConfirmed"].ToString());
- covid19Info.Add("WorldTotalDeaths", json["Global"]["TotalDeaths"].ToString());
- foreach (var country in JsonConvert.DeserializeObject<JObject>(data)["Countries"])
- {
- if(country["Country"].ToString() == "Viet Nam")
- {
- covid19Info.Add("VietnamTotalConfirmed", country["TotalConfirmed"].ToString());
- covid19Info.Add("VietnamTotalDeaths", country["TotalDeaths"].ToString());
- covid19Info.Add("VietnamTotalRecovered", country["TotalRecovered"].ToString());
- }
- }
- return covid19Info;
- }
- public List<string> ReadRssFeed()
- {
- List<string> feedTitle = new List<string>();
- foreach (var url in LoadRssFeed())
- {
- XmlReader reader = XmlReader.Create("https://vnexpress.net" + url);
- SyndicationFeed feed = SyndicationFeed.Load(reader);
- reader.Close();
- foreach (SyndicationItem item in feed.Items)
- {
- feedTitle.Add(item.Title.Text);
- }
- }
- return feedTitle;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement