-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
149 lines (139 loc) · 5.57 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
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
145
146
147
148
149
using NewsOutlet.basisClasses;
using System;
using System.IO;
using System.Runtime.CompilerServices;
using static NewsOutlet.basisClasses.FilesProcess;
namespace NewsOutlet
{
class Program
{
static void Main(string[] args)
{
FilesProcess filesProcess = new FilesProcess();
filesProcess.CreateSubJsonFiles();
DataManagement dataManagement = new DataManagement();
dataManagement.FillPQueue();
dataManagement.FillDictionary();
bool exit = false;
//DateTime now = DateTime.Now;
//long unixEpoch = dataManagement.convertToUnixEpoch(DateTime.Now);
Console.WriteLine("\n\tWelcome to NEWSOUTLET!");
while (!exit)
{
Console.WriteLine("\tSysTime > " + filesProcess.sysDate);
Console.WriteLine("\n\t\tMAIN MENU");
Console.WriteLine("\t1 - SHOW RECENT");
Console.WriteLine("\t2 - SHOW TRENDING");
Console.WriteLine("\t3 - SELECT");
Console.WriteLine("\t4 - BACK");
Console.WriteLine("\t5 - DISPLAY ALL NEWS");
Console.WriteLine("\t6 - SET TIME");
Console.WriteLine("\t7 - EXIT");
Console.Write("Please enter your options (1-6) > ");
int? cmd = Convert.ToInt32(Console.ReadLine());
switch (cmd)
{
case 1:
string[] keywordsRecent = askFilterByKeywords();
Console.WriteLine("\n +++++++ RECENT NEWS +++++++ ");
if (keywordsRecent.Length > 0)
{
dataManagement.DisplayRecentNewsByKeywords(keywordsRecent);
}
else
{
dataManagement.DisplayRecentNews();
}
break;
case 2:
string[] keywordsTrending = askFilterByKeywords();
Console.WriteLine("\n +++++++ TRENDING NEWS +++++++ ");
if (keywordsTrending.Length > 0)
{
dataManagement.DisplayTrendNewsByKeywords(keywordsTrending);
}
else
{
dataManagement.DisplayTrendNews();
}
dataManagement.FillPQueue();
break;
case 3:
Console.Write("Please enter the newsID you want to select > ");
int id = Convert.ToInt32(Console.ReadLine());
if (dataManagement.dictOfAllNews.ContainsKey(id))
{
dataManagement.Select(id);
dataManagement.PushNewsToStack(id);
}
else
{
Console.WriteLine("No News found with this ID");
}
break;
case 4:
int prevId = dataManagement.PopNewsFromStack();
if (prevId == -1)
{
break;
}
dataManagement.Select(prevId);
break;
case 5:
Console.WriteLine("\n +++++++ ALL NEWS +++++++");
dataManagement.DisplayAllNews();
break;
case 6:
filesProcess.sysDate = askTime();
filesProcess.ResetNewsFileByTime();
dataManagement.FillDictNewsByTime();
break;
default:
exit = true;
Console.WriteLine("Exiting....");
break;
}
}
Console.ReadKey();
}
private static string[] askFilterByKeywords()
{
Console.Write("Do you want to filter by keywords? (y/n) > ");
string[] keywords;
char? input;
try
{
input = Convert.ToChar(Console.ReadLine());
if (input.Equals('y') || input.Equals('Y'))
{
Console.Write("Please enter keywords (seperated by comma) > ");
string? kws = Console.ReadLine();
if (kws != null)
{
kws = kws.Trim();
keywords = kws.Split(',');
return keywords;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return new string[0];
}
private static DateTime askTime()
{
Console.WriteLine("System Current Time now > " + DateTime.Now);
Console.Write("Please enter the time to set (yyyy-MM-dd HH:mm:ss) > ");
string? dateString = Console.ReadLine();
if (dateString != null)
{
DateTime desiredTime = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", null);
Console.WriteLine("Updated Time > " + desiredTime);
return desiredTime;
}
return DateTime.Now;
}
}
}