-
Notifications
You must be signed in to change notification settings - Fork 0
/
draftCheck.py
123 lines (100 loc) · 4.57 KB
/
draftCheck.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
import requests, traceback, re, getpass
credentials = {'password': None,
'login': '[email protected]',
'redirect_uri': 'https://fantasy.premierleague.com/a/login',
'app': 'plfpl-web'
}
team_id = 5962010
if team_id == None or credentials['login'] == None:
while True:
print ("Enter team ID: ", end = '')
team_id = input()
try:
int(team_id)
except:
print("Your game id is an all integer code")
continue
print ("Email: ", end = '')
email = input()
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email)
if match == None:
print('Bad email please re-enter')
continue
credentials['login'] = email
print ("Password: ", end = '')
credentials['password'] = getpass.getpass()
break
else:
print ("Password: ", end = '')
credentials['password'] = getpass.getpass()
#Bootstrap API
bootstrap_url = 'https://fantasy.premierleague.com/api/bootstrap-static/'
get_data_bootstrap = requests.get(bootstrap_url).json()
#Establish session
session = requests.session()
session.post('https://users.premierleague.com/accounts/login/', data=credentials)
#Team API
team_api = 'https://fantasy.premierleague.com/api/my-team/%s/' % (team_id)
get_data_team = session.get(team_api).json()
sp = ' '
print('\n')
print('{0: >47}'.format("+/-"), '{0:>11}'.format('Purchase'), '{0: >8}'.format('Chance'))
print('Name', '{0:>36}'.format('Price'), '{0: >6}'.format('(GW)'), '{0: >7}'.format('Price'), '{0: >11}'.format('NextGW'), '{0: >7}'.format("News\n"))
for j in range(len(get_data_team['picks'])):
id = get_data_team['picks'][j]['element']
multiplier = get_data_team['picks'][j]['multiplier']
vice_captain = get_data_team['picks'][j]['is_vice_captain']
position = get_data_team['picks'][j]['position']
if multiplier == 2:
player_status = "(C)"
elif multiplier == 3:
player_status = "(TC)"
elif vice_captain == True:
player_status = "(VC)"
elif multiplier == 0:
player_status = "(Bench)"
else:
player_status = ""
for i in range(len(get_data_bootstrap['elements'])):
if get_data_bootstrap['elements'][i]['id'] == id:
name = get_data_bootstrap['elements'][i]['web_name']
price = get_data_bootstrap['elements'][i]['now_cost'] / 10
price_change = get_data_bootstrap['elements'][i]['cost_change_event'] / 10
next_round = get_data_bootstrap['elements'][i]['chance_of_playing_next_round']
if next_round == None:
next_round = 100
news = get_data_bootstrap['elements'][i]['news']
print("%-25s %-9s %-7.1f %-6.1f %-10.1f %-8d %s" %
(name, player_status, price, price_change, (get_data_team['picks'][j]['purchase_price'] / 10),next_round, news))
break
print ("\nFree transfers: %d" % (get_data_team['transfers']["limit"]))
print("Transfers used: %d" % get_data_team['transfers']["made"])
print ("Team value: £%.1fM" % (get_data_team['transfers']["value"] / 10))
print ("Money in da bank: £%.1fM" % (get_data_team['transfers']["bank"] / 10))
print("\nWildcard: %s" % ("Yes" if len(get_data_team["chips"][0]["played_by_entry"]) == 0 else "No"))
print("Free hit: %s" % ("Yes" if len(get_data_team["chips"][1]["played_by_entry"]) == 0 else "No"))
print("Bench boost: %s" % ("Yes" if len(get_data_team["chips"][2]["played_by_entry"]) == 0 else "No"))
print("Triple captain: %s" % ("Yes" if len(get_data_team["chips"][2]["played_by_entry"]) == 0 else "No"))
#Transfers
#Latest transfers API
latest_transfer_url = 'https://fantasy.premierleague.com/api/entry/%s/transfers-latest/' % (team_id)
get_latest_transfer = session.get(latest_transfer_url).json()
print('\nTransfers:')
print('Player out' + 21*sp + 'Player in\n')
for j in range(len(get_latest_transfer)):
trade = get_latest_transfer[j]
flag_in = False
flag_out = False
name_in = None
name_out = None
i = 0
while flag_out == False or flag_in == False:
if flag_in == False and get_data_bootstrap['elements'][i]['id'] == trade["element_in"]:
name_in = get_data_bootstrap['elements'][i]['web_name']
flag_in = True
if flag_out == False and get_data_bootstrap['elements'][i]['id'] == trade['element_out']:
name_out = get_data_bootstrap['elements'][i]['web_name']
flag_out = True
i += 1
print("%-30s %s" % (name_out, name_in))
print()