Skip to content

Commit

Permalink
Fix team_players stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturn committed Jan 14, 2019
1 parent a3541a7 commit 7b4267e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
7 changes: 3 additions & 4 deletions soccer/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ def get_team_players(self, team):
"""
team_id = self.team_names.get(team, None)
try:
req = self._get('teams/{team_id}/players'.format(
team_id=team_id))
team_players = req.json()
if int(team_players["count"]) == 0:
req = self._get('teams/{}/'.format(team_id))
team_players = req.json()['squad']
if not team_players:
click.secho("No players found for this team", fg="red", bold=True)
else:
self.writer.team_players(team_players)
Expand Down
23 changes: 13 additions & 10 deletions soccer/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def live_scores(self, live_scores, use_12_hour_format):

def team_scores(self, team_scores, time, show_datetime, use_12_hour_format):
"""Prints the teams scores in a pretty format"""
import ipdb; ipdb.set_trace()
for score in team_scores["matches"]:
if score["status"] == "FINISHED":
click.secho("%s\t" % score["utcDate"].split('T')[0],
Expand All @@ -93,12 +92,13 @@ def team_scores(self, team_scores, time, show_datetime, use_12_hour_format):

def team_players(self, team):
"""Prints the team players in a pretty format"""
players = sorted(team['players'], key=lambda d: (d['jerseyNumber']))
click.secho("%-4s %-25s %-20s %-20s %-15s %-10s" %
("N.", "NAME", "POSITION", "NATIONALITY", "BIRTHDAY",
"MARKET VALUE"), bold=True, fg=self.colors.MISC)
fmt = (u"{jerseyNumber:<4} {name:<28} {position:<23} {nationality:<23}"
u" {dateOfBirth:<18} {marketValue}")
players = sorted(team, key=lambda d: d['shirtNumber'])
click.secho("%-4s %-25s %-20s %-20s %-15s" %
("N.", "NAME", "POSITION", "NATIONALITY", "BIRTHDAY"),
bold=True,
fg=self.colors.MISC)
fmt = (u"{shirtNumber:<4} {name:<28} {position:<23} {nationality:<23}"
u" {dateOfBirth:<18}")
for player in players:
click.secho(fmt.format(**player), bold=True)

Expand Down Expand Up @@ -247,9 +247,12 @@ def team_players(self, team):
'Date of Birth', 'Market Value']
result = [headers]

result.extend([player['jerseyNumber'], player['name'],
player['position'], player['nationality'],
player['dateOfBirth'], player['marketValue']]
result.extend([player['shirtNumber'],
player['name'],
player['position'],
player['nationality'],
player['dateOfBirth'],
player['marketValue']]
for player in team['players'])
self.generate_output(result)

Expand Down

0 comments on commit 7b4267e

Please sign in to comment.