-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulae_database.py
80 lines (54 loc) · 2.1 KB
/
populae_database.py
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
from pathlib import Path
import os
import datetime
import time
import logging
import json
import pickle
from classes.MatchScraper import MatchScraper
from classes.CalendarScraper import CalendarScraper
def get_players_from_match(url):
ms = MatchScraper(url)
df, team_stats = ms.get_match_snapshot()
return df, team_stats
def download_entry_dataset(games):
teams_with_players = {}
for i, row in games.iterrows():
print(row.home, row.away, row.competition)
try:
ps, ts = get_players_from_match(row.link)
if len(ps) > 0:
grouped = ps.groupby(['team', 'players']).count().index.tolist()
if len(ps.players.unique()) != len(ps.players):
print(row.home, row.away, row.competition, 'hasa omonymus')
break
for team_player_pair in grouped:
team = team_player_pair[0]
player = team_player_pair[1]
if team not in teams_with_players.keys():
teams_with_players[team] = [player]
else:
if player not in teams_with_players[team]:
teams_with_players[team].append(player)
except AttributeError:
print(row.link)
return teams_with_players
if __name__ == '__main__':
url_live = 'https://www.rugbypass.com/live/'
cs = CalendarScraper(url_live)
games = cs.get_games_df()
games = games[games.date < datetime.datetime.now()]
teams_with_players = download_entry_dataset(games)
output = open('./Data/players_per_team.pickle', 'wb')
pickle.dump(teams_with_players, output)
output.close()
file = open("./Data/players_per_team.pickle", 'rb')
teams_with_players = dict(pickle.load(file))
file.close()
file = open("./Data/team_club_national.csv", "w+")
file.write('team,type\n')
for i,team in enumerate(teams_with_players.keys()):
print(team, str(i)+'/'+str(len(teams_with_players.keys())))
a = input()
file.write(team +','+a+'\n')
file.close()