-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
77 lines (62 loc) · 2.84 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
using SpielInsights;
using System.Collections.Generic;
using System.Text;
namespace Inaugurals
{
class Program
{
static void Main(string[] args)
{
string inputList = args[0];
string apiKey = args[1];
string outputFileName = args[2];
var client = new HttpClient();
//Output file
System.IO.StreamWriter outputFile = new System.IO.StreamWriter(outputFileName);
Task.Run(async () =>
{
using (StreamReader reader = new StreamReader(inputList))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Spiel spiel = new Spiel();
string[] components = line.Split(";");
spiel.Speaker = components[0];
spiel.SourceURI = components[1];
spiel.Date = System.Convert.ToDateTime(components[2]);
Console.WriteLine("Processing Inaugural: " + components[1]);
var response = await client.GetAsync(components[1]);
var content = await response.Content.ReadAsStringAsync();
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(content);
foreach (HtmlNode node in htmlDocument.DocumentNode.SelectNodes("//span[@class='displaytext']"))
{
HtmlDocument innerHtmlDocument = new HtmlDocument();
innerHtmlDocument.LoadHtml(node.InnerHtml);
foreach (HtmlNode pnode in innerHtmlDocument.DocumentNode.SelectNodes("//text()"))
{
string paragraphText = pnode.InnerText.Trim();
spiel.Paragraphs.Add(paragraphText);
}
SpielAnalytics analytics = SpielInsights.SpielInsights.AnalyzeSpiel(spiel, apiKey);
//Build semicolon separated output records
StringBuilder osb = new StringBuilder();
osb.Append(components[0] + ";"); //Speaker
osb.Append(components[2] + ";"); //Date
osb.Append(analytics.SummaryAnalytics.Sentiment);
outputFile.WriteLine(osb.ToString());
Console.WriteLine(osb.ToString());
}
}
}
}).GetAwaiter().GetResult();
outputFile.Close();
}
}
}