aboutsummaryrefslogtreecommitdiff
path: root/Main/Jobs/AggregatorJob.cs
diff options
context:
space:
mode:
authorAryadev Chavali <aryadevchavali1@gmail.com>2019-02-21 18:18:36 +0000
committerAryadev Chavali <aryadevchavali1@gmail.com>2019-02-21 18:18:36 +0000
commitcb849fe4aeef9d1e9bc41969d1c96c47ebcbc84d (patch)
tree034a775fbafbb569ff6115f480915f76b9ad570c /Main/Jobs/AggregatorJob.cs
parentf3f92c577d4c0ceb87f8a1e5743812371e89f40a (diff)
downloadnewsaggregator-cb849fe4aeef9d1e9bc41969d1c96c47ebcbc84d.tar.gz
newsaggregator-cb849fe4aeef9d1e9bc41969d1c96c47ebcbc84d.tar.bz2
newsaggregator-cb849fe4aeef9d1e9bc41969d1c96c47ebcbc84d.zip
Created static class for Aggregator service
Diffstat (limited to 'Main/Jobs/AggregatorJob.cs')
-rw-r--r--Main/Jobs/AggregatorJob.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Main/Jobs/AggregatorJob.cs b/Main/Jobs/AggregatorJob.cs
new file mode 100644
index 0000000..dc7c354
--- /dev/null
+++ b/Main/Jobs/AggregatorJob.cs
@@ -0,0 +1,57 @@
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+using Classes;
+using Database;
+using Aggregator;
+
+namespace Main.Jobs {
+ public static class AggregatorJob {
+ private static List<Config> configs = new List<Config> {
+ new Config {
+ Source = "BBC",
+ Title = 0,
+ Description = 1,
+ ArticleLink = 2,
+ ImageLink = 5,
+ PublishDate = 4
+ },
+ new Config {
+ Source = "Sky",
+ Title = 0,
+ Description = 2,
+ ArticleLink = 1,
+ ImageLink = 7,
+ PublishDate = 3
+ },
+ new Config {
+ Source = "ABC",
+ Title = 7,
+ Description = 11,
+ ArticleLink = 8,
+ ImageLink = 0,
+ PublishDate = 10
+ }
+ };
+
+ private static List<string> sites = new List<string> {
+ "http://feeds.bbci.co.uk/news/rss.xml",
+ "http://feeds.skynews.com/feeds/rss/world.xml",
+ "https://abcnews.go.com/abcnews/topstories"
+ };
+
+ public static async void Process(DatabaseContext context) {
+ var articles = await parseMultiple();
+ await context.InsertArticles(articles);
+ }
+
+ private static async Task<List<Article>> parseMultiple() {
+ var xmls = new List<string>();
+ foreach (string site in sites) {
+ xmls.Add(await Download.DownloadXML(site));
+ }
+
+ return ParserService.ParseMultiple(xmls.ToArray(), configs).ToList();
+ }
+ }
+} \ No newline at end of file