-
Notifications
You must be signed in to change notification settings - Fork 1
/
MatchParser.cs
207 lines (189 loc) · 7.85 KB
/
MatchParser.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;
namespace BloodBot
{
public class MatchParser
{
/// <summary>
/// Helper function that checks if the class of the node is equal to the given string
/// </summary>
bool CheckNodeClass(HtmlNode node, string text)
{
if (node.GetAttributeValue("class", "").Equals(text))
{
return (true);
}
else
{
return (false);
}
}
/// <summary>
/// Helper function that returns the numbers in a given string
/// </summary>
string GetNumbers(string text)
{
string numbers = "";
foreach (char c in text)
{
if (char.IsDigit(c))
{
numbers += c;
}
}
return numbers;
}
/// <summary>
/// Looks through the current matches on FUMBBL and gets all the matches in the desired section
/// </summary>
public Dictionary<string, Match> GetMatches()
{
Dictionary<string, Match> Matches = new Dictionary<string, Match>();
HtmlWeb web = new HtmlWeb();
HtmlDocument document = null;
int tries = 0;
bool success = false;
while (success == false)
{
try
{
document = web.Load("https://fumbbl.com/p/games");
success = true;
}
catch (Exception e)
{
tries++;
Logger.Log(DateTime.UtcNow + " fumbbl is kill, TRIES: " + tries);
System.Threading.Thread.Sleep(60000);
}
}
// div = navigator and where we start looking, Gamesfooter = end
HtmlNode div = document.DocumentNode.SelectSingleNode("//div[.='League tournaments']");
HtmlNode Gamesfooter = document.DocumentNode.SelectSingleNode("//div[@class='gamesfooter']");
// FUMBBL divisions
HtmlNode League = document.DocumentNode.SelectSingleNode("//div[.='League']");
HtmlNode Blackbox = document.DocumentNode.SelectSingleNode("//div[.='Blackbox']");
// storage variables to make new matches
string MatchID = "null";
string Tournament = "";
string Group = "";
string HomeCoach = "";
string HomeTeam = "";
string HomeRace = "";
string HomeTV = "";
string AwayCoach = "";
string AwayTeam = "";
string AwayRace = "";
string AwayTV = "";
string SpectatorLink = "";
while (/*(div != League) && (div != Blackbox) &&*/ (div != Gamesfooter) && (div != null))
{
// get tournament name
if (CheckNodeClass(div, "tournament"))
{
Tournament = div.ChildNodes["a"].InnerText;
Group = div.ChildNodes["a"].GetAttributeValue("href", "");
if (Group == "/p/group?op=view&group=9828") // main
{
Group = "/tg/ FUMBBL League";
}
else if (Group == "/p/group?op=view&group=10667") // monkey
{
Group = "/tg/ Monkey League";
}
else if (Group == "/p/group?op=view&group=10393") // secret
{
Group = "/tg/ Secret League";
}
else if (Group == "/p/group?op=view&group=10178") // stunty
{
Group = "/tg/ Stunty Leeg";
}
else if (Group == "/p/group?op=view&group=10591") // stall
{
Group = "/tg/ STALL";
}
else if (Group == "/p/group?op=view&group=10948") // gacha
{
Group = "Cuckrim Gacha Draft Paradise";
}
else if (Group == "/p/group?op=view&group=11066") // speed
{
Group = "/tg/ SPEED Bowl";
}
}
// get Match info
if (CheckNodeClass(div, "matchrecord withtournament"))
{
foreach (HtmlNode node in div.ChildNodes)
{
if (CheckNodeClass(node, "home"))
{
foreach (HtmlNode node2 in node.ChildNodes)
{
if (CheckNodeClass(node2, "team"))
{
HomeTeam = node2.InnerText;
}
else if (CheckNodeClass(node2, "race"))
{
HomeCoach = node2.ChildNodes["a"].InnerText;
HomeRace = node2.LastChild.InnerText;
}
}
}
else if (CheckNodeClass(node, "divider"))
{
foreach (HtmlNode node2 in node.ChildNodes)
{
//if (CheckNodeClass(node2, "progress"))
//{
// // time
// Logger.Log("Time: " + node2.FirstChild.InnerText);
//}
if (CheckNodeClass(node2, "spectate"))
{
// spectator link
//Logger.Log("Spectate: " + node2.ChildNodes["a"].GetAttributeValue("href", ""));
SpectatorLink = node2.ChildNodes["a"].GetAttributeValue("href","");
MatchID = GetNumbers(node2.ChildNodes["a"].GetAttributeValue("href", ""));
}
}
}
else if ((CheckNodeClass(node, "away")))
{
foreach (HtmlNode node2 in node.ChildNodes)
{
if (CheckNodeClass(node2, "team"))
{
AwayTeam = node2.InnerText;
}
else if (CheckNodeClass(node2, "race"))
{
AwayCoach = node2.ChildNodes["a"].InnerText;
AwayRace = node2.FirstChild.InnerText;
}
}
}
}
}
//update or create match
if (CheckNodeClass(div, "matchrecord withtournament"))
{
if (Group.StartsWith("/tg/") || Group.StartsWith("Cuckrim"))
{
Matches[MatchID] = new Match(MatchID, Tournament, HomeCoach, HomeTeam, HomeRace, HomeTV, AwayCoach, AwayTeam, AwayRace, AwayTV, SpectatorLink, Group);
}
MatchID = "null";
}
div = div.NextSibling;
}
if (div == null) Logger.Log(DateTimeOffset.UtcNow +" no matches being played");
return Matches;
}
}
}