-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (53 loc) · 2.11 KB
/
Copy pathmain.py
File metadata and controls
74 lines (53 loc) · 2.11 KB
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
import os
from operator import itemgetter
from utils import Games
from utils.Bets import Bets
from utils.DingTalk import DingtalkRobot
from config.config import cfg
# Get Match Results
fixtures = Games.get_fixtures()
games_results = []
for ids, game in enumerate(fixtures):
if game['matchday'] > 4:
continue
result = 'X'
if game['result']['goalsHomeTeam'] > game['result']['goalsAwayTeam']:
result = '1'
if game['result']['goalsHomeTeam'] < game['result']['goalsAwayTeam']:
result = '2'
if 'penaltyShootout' in game['result']:
if game['result']['penaltyShootout']['goalsHomeTeam'] > game['result']['penaltyShootout']['goalsAwayTeam']:
result = '1'
if game['result']['penaltyShootout']['goalsHomeTeam'] < game['result']['penaltyShootout']['goalsAwayTeam']:
result = '2'
if game['status'] != 'FINISHED':
result = 'TIMED'
print("Match {} :: {} - {} :: {}".format(ids, game['homeTeamName'], game['awayTeamName'], result))
if game['status'] != 'FINISHED':
continue
games_results.append(result)
print('Current finished game: {}'.format(len(games_results)))
# Get Bets
current_folder = os.path.dirname(os.path.realpath(__file__))
bets_file = os.path.join(current_folder, 'bets.csv')
players_bets = Bets(bets_file).get_all_bets()
# Compute score
## Init score
players_scores = {}
for player in players_bets:
players_scores[player['employee_username']] = 0
for game_id, game_score in enumerate(games_results):
for player_id, player in enumerate(players_bets):
if players_bets[player_id]['bets'][game_id] == game_score:
players_scores[player['employee_username']] += Games.get_match_weight(game_id)
print players_scores
# Sort results
sorted_results = sorted(players_scores.items(), key=itemgetter(1), reverse=True)
# Print to DingTalk
robot = DingtalkRobot(token=cfg['DINGTALK_TOKEN'])
msg = 'Please find current statistics:\n'
msg += 'Current finished game: {}\n\n'.format(len(games_results))
for score in sorted_results:
msg += '{}:\t\t{}\n'.format(score[0], score[1])
print(msg)
#robot.send_text(msg)