-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartActivePlayers.py
84 lines (72 loc) · 2.51 KB
/
startActivePlayers.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
try:
from configparser import ConfigParser # python 3
except ImportError:
from ConfigParser import ConfigParser # python 2.7
import sys
import fantasy_login as login
import fantasy_team as tm
from urlparse import urljoin
from datetime import datetime, date, timedelta
def usage():
"""
Print usage and exit
"""
msg_lines = [' username and password is empty ']
sys.exit('\n\n'.join(msg_lines))
def output_team_info(session, league_id, team_id):
"""
Output team name and league
"""
response = session.get(tm.url('nba', league_id, team_id))
league = tm.league(response.text)
team = tm.team(response.text)
print("Success!")
print('League Name: %s \nTeam Name: %s\n' % (league, team))
def start_active_players(session, league_id, team_id, start_date=None):
"""
Start active players and output results
"""
# Load team page
team_url = tm.url('nba', league_id, team_id, start_date)
response = session.get(team_url)
# Press "Start Active Players" button
start_path = tm.start_active_players_path(response.text)
start_url = urljoin(response.url, start_path)
response = session.get(start_url)
# If unsuccessful, report failure
formatted_date = tm.date(response.text)
if not (200 <= response.status_code < 300):
print('- %s: Failed to start active players' % formatted_date)
# Report success and highlight available bench players
print('- %s: Started active players' % formatted_date)
alternates = tm.alternates(response.text)
for player in alternates:
print(' - Alternate: %s (%s) [%s]' % (
player['name'],
player['details'],
player['opponent']))
def main():
config = ConfigParser()
config.read('config.ini')
username = config.get('LOGIN INFO', 'USERNAME')
password = config.get('LOGIN INFO', 'PASSWORD')
league_id = config.get('FANTASY INFO', 'LEAGUE_ID')
team_id = config.get('FANTASY INFO', 'TEAM_ID')
if username is None or password is None:
usage()
try:
print("Loading...Please wait...")
session = login.authenticated_session(username, password)
output_team_info(session, league_id, team_id)
except:
sys.exit("Login Failed")
start_date = date.today()
num_days = input("Enter number of days you want to start your active players: ")
try:
for _ in range(num_days):
start_active_players(session, league_id, team_id, start_date)
start_date = start_date + timedelta(days=1)
except:
sys.exit("Faild To Start Players")
if __name__ == '__main__':
main()