-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
139 lines (112 loc) · 5.11 KB
/
Program.cs
File metadata and controls
139 lines (112 loc) · 5.11 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using HtmlAgilityPack;
using Figgle;
using Colorful;
using System.Drawing;
using System.Web;
using Console = System.Console;
namespace CodeJam4
{
internal class Program
{
public static HtmlDocument LoadUrl(string fileUrl)
{
var url = fileUrl;
var web = new HtmlWeb();
return web.Load(url);
}
public static void GrabHeadline(HtmlDocument doc)
{
var title = doc.DocumentNode
.SelectSingleNode("//h1[contains(@class, 'article-hero-headline__htag')]");
if (title != null)
{
//Colorful.Console.WriteLine(title.InnerHtml, Color.FromArgb(255, 255, 250));
Colorful.Console.WriteWithGradient(title.InnerHtml, Color.HotPink, Color.RebeccaPurple, 4);
}
else
{
Colorful.Console.WriteLine("No title");
}
}
public static void PrintContent(HtmlDocument doc)
{
var subTitleNodes = doc.DocumentNode
.SelectNodes("//h2[contains(@class, 'styles_chartCardHeadline__aiJF0')]");
var subTitleContentNodes = doc.DocumentNode
.SelectNodes("//div[@data-icid]");
List<string> subTitles = new List<string>();
List<List<string>> subTitleContents = new List<List<string>>();
//Getting all Sub Headings
if (subTitles != null)
{
foreach (var subtitle in subTitleNodes)
{
//Colorful.Console.WriteLine(HtmlEntity.DeEntitize(subtitle.InnerHtml));
subTitles.Add(HtmlEntity.DeEntitize(subtitle.InnerHtml));
}
}
else
{
Colorful.Console.WriteLine("No Subtitles Found", Color.PaleVioletRed);
}
//Getting Content from each subheading.
if (subTitleContentNodes != null) // Some of the headlines that contains apostrophes show an error in the middle of the word (ex. "What's the most valuable NFL franchise?"
// Finding a way to be able to show the apostrophe properly should be an easy fix
{
foreach (var subTitleContentNode in subTitleContentNodes)
{
var pNodes = subTitleContentNode.SelectNodes(".//p");
if(pNodes != null)
{
List<string> pNodesContent = new List<string>();
foreach (var p in pNodes)
{
HtmlDocument temp = new HtmlDocument();
temp.LoadHtml(p.InnerHtml);
string cleanText = temp.DocumentNode.InnerText;
cleanText = HttpUtility.HtmlDecode(cleanText);
pNodesContent.Add(HtmlEntity.DeEntitize(cleanText));
}
subTitleContents.Add(pNodesContent);
}
}
}
for (int i = 0; i < subTitles.Count; i++)
{
// for some of the articles, the contents don't show past the article title, might have to be reviewed with more test cases to see why that is
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(subTitles[i], Color.Aquamarine); // prints the subtitle
Console.ResetColor();
List<string> contents = subTitleContents[i];
Colorful.Console.WriteLine("----------------------------------------\n");
for (int h = 0; h < contents.Count; h++)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(contents[h] + "\n", Color.CornflowerBlue);
Console.ResetColor();// prints the content within the subtitle
}
Console.ResetColor();
Console.WriteLine("----------------------------------------\n");
}
}
static void Main(string[] args)
{
//System.Console.BackgroundColor = ConsoleColor.Gray;
bool vrajMode = false;
string figletText = FiggleFonts.Standard.Render("NBC News Outliner!");
Colorful.Console.WriteWithGradient(figletText, Color.LemonChiffon, Color.AliceBlue);
Console.WriteLine("Enter Vraj Mode? [Y/N]");
string ans = Console.ReadLine();
if (ans.Equals('Y'))
{
vrajMode = true;
System.Console.BackgroundColor = ConsoleColor.Red;
}
Colorful.Console.WriteLine("Enter the url of a NBC live coverage news article that you want to create an outline of:", Color.Fuchsia);
string? url = Colorful.Console.ReadLine();
var doc = LoadUrl(url);
GrabHeadline(doc);
PrintContent(doc);
}
}
}