-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
144 lines (117 loc) · 5.04 KB
/
Program.cs
File metadata and controls
144 lines (117 loc) · 5.04 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
140
141
142
143
144
using HtmlAgilityPack;
using Figgle;
using Colorful;
using System.Drawing;
using System.Web;
using Console = System.Console;
//using System.Threading;
namespace CodeJam4
{
internal class Program
{
public static HtmlDocument LoadUrl(string fileUrl)
{
var url = fileUrl;
var web = new HtmlWeb();
return web.Load(url);
}
/// Add a simple divider line to separate different sections
//public static void PrintDivider(char dividerChar = '-')
//{
// string divider = new string(dividerChar, Console.WindowWidth);
// Colorful.Console.WriteLine(divider, Color.Pink); // Highlight change with pink divider
//}
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)
{
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++)
{
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);
}
}
}