aboutsummaryrefslogtreecommitdiff
path: root/Main/Jobs/AggregatorJob.cs
diff options
context:
space:
mode:
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