-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service1.cs
249 lines (203 loc) · 8.56 KB
/
Service1.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Text;
using System.Net;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Collections.Generic;
using KSULax.Entities;
using KSULax.Dal;
using KSULax.Logic.Import;
using HtmlAgilityPack;
namespace MCLAImport
{
public partial class Service1
{
public static void Main(string[] args)
{
importMCLA();
//importMCLATop23();
//importCLTop25();
}
private static void importMCLATop23()
{
string url = "http://mclamag.com/top23/"+DateTime.Now.Year;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
HtmlDocument doc = new HtmlDocument();
doc.Load(httpResponse.GetResponseStream());
short pollSourceId = 1;
DateTime pollDate = DateTime.Parse(doc.DocumentNode.SelectSingleNode("//h3").InnerText);
string pollUrl = url +@"/" + doc.DocumentNode.SelectSingleNode("//li/a[contains(@class, 'active')]").Attributes["href"].Value;
short rank = 0;
short index = 1;
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//ol[@class='div2']/li/span/a/img[@src]"))
{
HtmlAttribute att = link.Attributes["src"];
if (att.Value.Contains("kennesaw_state"))
{
rank = index;
break;
}
index++;
}
if (rank > 0)
{
DataBL dbl = new DataBL();
dbl.UpdatePoll(new TeamRankingBE
{
Date = pollDate,
pollSource = pollSourceId,
Rank = rank,
Url = pollUrl
}
);
}
}
private static void importCLTop25()
{
string root = "http://www.collegelax.us";
string url = root + "/polls.php";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
HtmlDocument doc = new HtmlDocument();
doc.Load(httpResponse.GetResponseStream());
short pollSourceId = 2;
string h4 = doc.DocumentNode.SelectSingleNode("//h4").InnerText;
DateTime pollDate = DateTime.Parse(h4.Substring(h4.LastIndexOf(' '))+ '/' + DateTime.Now.Year );
string pollUrl = root + doc.DocumentNode.SelectSingleNode("//ul[@class='News']/li/a[@href]").Attributes["href"].Value;
short rank = 0;
HtmlNode tr = doc.DocumentNode.SelectSingleNode("//tr/td/a[contains(@href,'kennesaw_state')]").ParentNode.ParentNode;
if (short.TryParse(tr.FirstChild.InnerText, out rank))
{
DataBL dbl = new DataBL();
dbl.UpdatePoll(new TeamRankingBE
{
Date = pollDate,
pollSource = pollSourceId,
Rank = rank,
Url = pollUrl
}
);
}
}
#region MCLA
private static void importMCLA()
{
//string url = "http://api.mcla.us/request/?api_key=f62001122589294193682bb5ac6897c7&version=1.1&method=game&team=kennesaw_state";
//string url = "http://api.mcla.us/request/?api_key=f62001122589294193682bb5ac6897c7&version=1.1&method=roster&team=kennesaw_state";
//string url = "http://api.mcla.us/request/?api_key=f62001122589294193682bb5ac6897c7&version=1.1&method=game&start=02/12/2011&end=02/14/2011&team=kennesaw_state";
//string url = "http://mcla.us/scores/games/6353/";
//HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
//HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
MCLA mcla = new MCLA();
XmlDocument responseXML = new XmlDocument();
//responseXML.Load(httpResponse.GetResponseStream());
responseXML.Load(@"C:\Users\Brett\Documents\Visual Studio 2010\Projects\MCLAImport\xml\Roster.xml");
var players = roster.Deserialize(responseXML.InnerXml);
var pbeLst = GetPlayerBE(players.player);
if (null != pbeLst)
{
mcla.UpdatePlayers(pbeLst);
}
//responseXML.Load(httpResponse.GetResponseStream());
responseXML.Load(@"C:\Users\Brett\Documents\Visual Studio 2010\Projects\MCLAImport\xml\Schedule.xml");
var sch = schedule.Deserialize(responseXML.InnerXml);
var geLst = GetGameBE(sch.game);
var pgbeLst = GetGameStatBE(sch.game);
if (null != geLst)
{
mcla.UpdateGames(geLst);
if (null != pgbeLst)
{
mcla.UpdateGameStatByGame(pgbeLst);
}
}
}
private static List<GameStatBE> GetGameStatBE(List<scheduleGame> games)
{
var pgbeLst = new List<GameStatBE>();
foreach (scheduleGame game in games)
{
bool _isHome = game.home_team_slug.Equals("kennesaw_state");
pgbeLst.AddRange(GetGameStatBE(_isHome ? game.home_players : game.away_players, game.id, game.game_season_id));
}
return pgbeLst;
}
private static List<GameStatBE> GetGameStatBE(List<PlayerGameStat> players, ushort gameID, ushort seasonID)
{
var pgbeLst = new List<GameStatBE>();
foreach (PlayerGameStat player in players)
{
pgbeLst.Add(new GameStatBE
{
Assists = player.assists,
GameID = gameID,
Goals = player.goals,
GoalsAgainst = player.ga,
PlayerID = player.id,
Saves = player.saves,
SeasonID = seasonID
});
}
return pgbeLst;
}
private static List<GameBE> GetGameBE(List<scheduleGame> games)
{
var gbeLst = new List<GameBE>();
foreach (scheduleGame game in games)
{
gbeLst.Add(GetGameBE(game));
}
return gbeLst;
}
private static GameBE GetGameBE(scheduleGame game)
{
var ge = new GameBE
{
AwayTeamScore = game.away_team_score,
AwayTeamSlug = game.away_team_slug,
Datetime = DateTime.Parse(game.game_date + ' ' + game.game_season_id + ' '+ game.game_time),
SeasonID = (short)game.game_season_id,
Status = game.game_status,
Type = game.game_type,
HomeTeamScore = game.home_team_score,
HomeTeamSlug = game.home_team_slug,
ID = (short)game.id,
Venue = game.venue
};
return ge;
}
private static List<PlayerBE> GetPlayerBE(List<rosterPlayer> players)
{
var pbeLst = new List<PlayerBE>();
foreach (rosterPlayer player in players)
{
pbeLst.Add(GetPlayerBE(player));
}
return pbeLst;
}
private static PlayerBE GetPlayerBE(rosterPlayer player)
{
PlayerBE pbe = new PlayerBE();
pbe.FirstName = player.first;
pbe.HighSchool = player.highschool;
pbe.HomeState = player.homestate;
pbe.Hometown = player.hometown;
pbe.PlayerID = player.id;
pbe.LastName = player.last;
pbe.Major = player.major;
pbe.MiddleName = player.middle;
pbe.ClassYr = player.season.@class;
pbe.EligibilityYr = player.season.eligibility;
pbe.Height = player.season.height;
pbe.SeasonID = player.season.id;
pbe.JerseyNum = player.season.jersey;
pbe.Position = player.season.position;
pbe.Weight = player.season.weight;
pbe.Team = player.season.team;
return pbe;
}
#endregion MCLA
}
}