-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
151 lines (126 loc) · 7.14 KB
/
main.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
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
import match_dates
import time
import twitter
import traceback
from datetime import datetime
from LiveScore import LiveScore, Game
from typing import List
match_dates = match_dates.match_dates
def tweet():
team = "Bayern Munich"
todays_date = int(datetime.today().strftime("%Y%m%d"))
todays_id = match_dates[todays_date][0]
if todays_date in match_dates.keys():
match_dictionary = {
"date": todays_date,
"id": match_dates[todays_date][0],
"start time": match_dates[todays_date][1],
"competition": 0,
"home team": 0,
"home team code": match_dates[todays_date][2],
"home score": 0,
"away team": 0,
"away team code": match_dates[todays_date][3],
"away score": 0,
"minute": 0,
"team": 0,
"player": 0,
"event type": 0,
"event count": 0,
"event id": 0,
"status": 0
}
livescore = LiveScore()
match_info: List[Game] = livescore.getGames(todays_date, team)
competition = match_info[0].competition
match_dictionary.update({"competition": competition})
home_team = match_info[0].home_team
match_dictionary.update({"home team": home_team})
away_team = match_info[0].away_team
match_dictionary.update({"away team": away_team})
twitter.tweet(match_dictionary)
print(match_dictionary)
event_log = []
event_dictionary = {
"event type": match_dictionary["event type"],
"event_id": match_dictionary["event id"],
"minute": match_dictionary["minute"]
}
event_log.append(event_dictionary)
match_dictionary["event count"] += 1
while match_dictionary["status"] != "FT":
match_events = livescore.getGameInPlay(todays_id)
if match_events:
print(match_events)
if match_events and match_events.events != None:
events = match_events.events
if events:
for event in events:
if event.team == match_dictionary["home team"]:
if event.event_type == "Goal" or event.event_type == "Own Goal" or event.event_type == "Penalty Goal":
match_dictionary.update({"home score": event.home_score_updated})
if event.event_type == "VAR":
match_dictionary.update({"home score": event.home_score_updated})
if event.team == match_dictionary["away team"]:
if event.event_type == "Goal" or event.event_type == "Own Goal" or event.event_type == "Penalty Goal":
match_dictionary.update({"away score": event.away_score_updated})
if event.event_type == "VAR":
match_dictionary.update({"away score": event.away_score_updated})
end_times = [45, 90, 105, 120]
minute = event.minute
if minute in end_times and event.minute_extra != None:
minute = str(minute) + "' + " + str(event.minute_extra)
match_dictionary.update({"minute": minute})
team = event.team
match_dictionary.update({"team": team})
player = event.player
match_dictionary.update({"player": player})
event_type = event.event_type
match_dictionary.update({"event type": event_type})
event_id = event.event_id
match_dictionary.update({"event id": event_id})
event_dictionary = {
"event type": match_dictionary["event type"],
"event_id": match_dictionary["event id"],
"minute": match_dictionary["minute"]
}
if event_dictionary not in event_log:
if player != None:
try:
event_log.append(event_dictionary)
match_dictionary["event count"] += 1
twitter.tweet(match_dictionary)
print(match_dictionary)
except Exception:
print(traceback.print_exc())
status = match_events.status
match_dictionary.update({"status": status})
if status == "HT" and not any(event['minute'] == "HT" for event in event_log):
try:
match_dictionary.update({"minute": status})
match_dictionary.update({"team": "ALL"})
match_dictionary.update({"player": "ALL"})
match_dictionary.update({"event type": status})
match_dictionary.update({"status": status})
match_dictionary.update({"minute": status})
event_log.append(event_dictionary)
twitter.tweet(match_dictionary)
print(match_dictionary)
except Exception:
print(traceback.print_exc())
if status == "FT":
try:
match_dictionary.update({"home score": match_events.home_score})
match_dictionary.update({"away score": match_events.away_score})
match_dictionary.update({"minute": status})
match_dictionary.update({"team": "ALL"})
match_dictionary.update({"player": "ALL"})
match_dictionary.update({"event type": status})
match_dictionary.update({"status": status})
twitter.tweet(match_dictionary)
print(match_dictionary)
return
except Exception:
print(traceback.print_exc())
time.sleep(120)
tweet = tweet()