@@ -63,19 +63,20 @@ def get_live_scores(writer, use_12_hour_format):
6363 click .secho ("There was problem getting live scores" , fg = "red" , bold = True )
6464
6565
66- def get_team_scores (team , time , writer ):
66+ def get_team_scores (team , time , writer , show_upcoming , use_12_hour_format ):
6767 """Queries the API and gets the particular team scores"""
6868 team_id = TEAM_NAMES .get (team , None )
69+ time_frame = 'n' if show_upcoming else 'p'
6970 if team_id :
7071 try :
71- req = _get ('teams/{team_id}/fixtures?timeFrame=p {time}' .format (
72- team_id = team_id , time = time ))
72+ req = _get ('teams/{team_id}/fixtures?timeFrame={time_frame} {time}' .format (
73+ team_id = team_id , time_frame = time_frame , time = time ))
7374 team_scores = req .json ()
7475 if len (team_scores ["fixtures" ]) == 0 :
7576 click .secho ("No action during past week. Change the time "
7677 "parameter to get more fixtures." , fg = "red" , bold = True )
7778 else :
78- writer .team_scores (team_scores , time )
79+ writer .team_scores (team_scores , time , show_upcoming , use_12_hour_format )
7980 except APIErrorException as e :
8081 click .secho (e .args [0 ],
8182 fg = "red" , bold = True )
@@ -98,32 +99,34 @@ def get_standings(league, writer):
9899 fg = "red" , bold = True )
99100
100101
101- def get_league_scores (league , time , writer ):
102+ def get_league_scores (league , time , writer , show_upcoming , use_12_hour_format ):
103+
102104 """
103105 Queries the API and fetches the scores for fixtures
104106 based upon the league and time parameter
105107 """
108+ time_frame = 'n' if show_upcoming else 'p'
106109 if league :
107110 try :
108111 league_id = LEAGUE_IDS [league ]
109- req = _get ('soccerseasons/{id}/fixtures?timeFrame=p {time}' .format (
110- id = league_id , time = str (time )))
112+ req = _get ('soccerseasons/{id}/fixtures?timeFrame={time_frame} {time}' .format (
113+ id = league_id , time_frame = time_frame , time = str (time )))
111114 fixtures_results = req .json ()
112115 # no fixtures in the past week. display a help message and return
113116 if len (fixtures_results ["fixtures" ]) == 0 :
114117 click .secho ("No {league} matches in the past week." .format (league = league ),
115118 fg = "red" , bold = True )
116119 return
117- writer .league_scores (fixtures_results , time )
120+ writer .league_scores (fixtures_results , time , show_upcoming , use_12_hour_format )
118121 except APIErrorException :
119122 click .secho ("No data for the given league." , fg = "red" , bold = True )
120123 else :
121124 # When no league specified. Print all available in time frame.
122125 try :
123- req = _get ('fixtures?timeFrame=p {time}' .format (
124- time = str (time )))
126+ req = _get ('fixtures?timeFrame={time_frame} {time}' .format (
127+ time_frame = time_frame , time = str (time )))
125128 fixtures_results = req .json ()
126- writer .league_scores (fixtures_results , time )
129+ writer .league_scores (fixtures_results , time , show_upcoming , use_12_hour_format )
127130 except APIErrorException :
128131 click .secho ("No data available." , fg = "red" , bold = True )
129132
@@ -160,6 +163,7 @@ def get_team_players(team, writer):
160163 "See team codes listed in README." ))
161164@click .option ('--time' , default = 6 ,
162165 help = "The number of days in the past for which you want to see the scores" )
166+ @click .option ('--upcoming' , is_flag = True , default = False , help = "Displays upcoming games when used with --time command." )
163167@click .option ('--stdout' , 'output_format' , flag_value = 'stdout' ,
164168 default = True , help = "Print to stdout" )
165169@click .option ('--csv' , 'output_format' , flag_value = 'csv' ,
@@ -168,7 +172,7 @@ def get_team_players(team, writer):
168172 help = 'Output in JSON format' )
169173@click .option ('-o' , '--output-file' , default = None ,
170174 help = "Save output to a file (only if csv or json option is provided)" )
171- def main (league , time , standings , team , live , use12hour , players , output_format , output_file ):
175+ def main (league , time , standings , team , live , use12hour , players , output_format , output_file , upcoming ):
172176 """A CLI for live and past football scores from various football leagues"""
173177 try :
174178 if output_format == 'stdout' and output_file :
@@ -192,10 +196,10 @@ def main(league, time, standings, team, live, use12hour, players, output_format,
192196 get_team_players (team , writer )
193197 return
194198 else :
195- get_team_scores (team , time , writer )
199+ get_team_scores (team , time , writer , upcoming , use12hour )
196200 return
197201
198- get_league_scores (league , time , writer )
202+ get_league_scores (league , time , writer , upcoming , use12hour )
199203 except IncorrectParametersException as e :
200204 click .secho (e .message , fg = "red" , bold = True )
201205
0 commit comments