Skip to content

Commit

Permalink
Merge branch 'new-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturn committed Jan 14, 2019
2 parents 6f7c39b + f8376b5 commit 7fdabcf
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 117 deletions.
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Soccer CLI

[![PyPI version](https://badge.fury.io/py/soccer-cli.svg)](http://badge.fury.io/py/soccer-cli) [![Join the chat at https://gitter.im/architv/soccer-cli](https://badges.gitter.im/architv/soccer-cli.svg)](https://gitter.im/architv/soccer-cli?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Soccer for Hackers - a CLI for all the football scores.
Soccer for Hackers - a CLI for all the football scores.

![](http://i.imgur.com/9QbcUrj.gif)

Expand Down Expand Up @@ -120,24 +120,20 @@ $ soccer --help
- Europe:
- CL: Champions League
- England:
- PL: Premier League
- EL1: League One
- PL: English Premier League
- ELC: English Championship
- France:
- FL: Ligue 1
- FL2: Ligue 2
- Germany:
- BL: Bundesliga
- BL2: 2. Bundesliga
- BL3: 3. Liga
- Italy:
- SA: Serie A
- SA: Serie A
- Netherlands:
- DED: Eredivisie
- Portugal:
- PPL: Primeira Liga
- Spain:
- LLIGA: La Liga
- SD: Segunda Division

### Team and team codes

Expand Down Expand Up @@ -174,13 +170,14 @@ Demo

Todo
====
- [ ] Enable cache
- [ ] Add more test cases
- [x] Add fixtures for UEFA Champions League
- [ ] Add league filter for live scores
- [x] Color coding for Europa league and differentiation between straight CL and CL playoff spots, and the same for EL spots
- [x] Add support for team line up
- [ ] Enable cache.
- [ ] Add more test cases.
- [x] Add fixtures for UEFA Champions League.
- [ ] Add league filter for live scores.
- [x] Color coding for Europa league and differentiation between straight CL and CL playoff spots, and the same for EL spots.
- [x] Add support for team line up.
- [ ] A built in watch feature so you can run once with --live and just leave the program running.
- [ ] Python 3 support.

Licence
====
Expand Down
21 changes: 9 additions & 12 deletions soccer/leagueids.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
LEAGUE_IDS = {
"BL": 452,
"BL2": 453,
"FL1": 450,
"FL2": 451,
"PL": 445,
"EL1": 447,
"ELC": 446,
"PD": 455,
"SA": 456,
"PPL": 457,
"DED": 449,
"CL": 464
"BL": 2002,
"FL1": 2015,
"PL": 2021,
"ELC": 2016,
"PD": 2014,
"SA": 2019,
"PPL": 2017,
"DED": 2003,
"CL": 2001
}
37 changes: 24 additions & 13 deletions soccer/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class RequestHandler(object):

BASE_URL = 'http://api.football-data.org/v1/'
BASE_URL = 'http://api.football-data.org/v2/'
LIVE_URL = 'http://soccer-cli.appspot.com/'

def __init__(self, headers, league_ids, team_names, writer):
Expand Down Expand Up @@ -33,11 +33,23 @@ def get_live_scores(self, use_12_hour_format):
"""Gets the live scores"""
req = requests.get(RequestHandler.LIVE_URL)
if req.status_code == requests.codes.ok:
scores_data = []
scores = req.json()
if len(scores["games"]) == 0:
click.secho("No live action currently", fg="red", bold=True)
return
self.writer.live_scores(scores, use_12_hour_format)

for score in scores['games']:
# match football-data api structure
d = {}
d['homeTeam'] = {'name': score['homeTeamName']}
d['awayTeam'] = {'name': score['awayTeamName']}
d['score'] = {'fullTime': {'homeTeam': score['goalsHomeTeam'],
'awayTeam': score['goalsAwayTeam']}}
d['league'] = score['league']
d['time'] = score['time']
scores_data.append(d)
self.writer.live_scores(scores_data)
else:
click.secho("There was problem getting live scores", fg="red", bold=True)

Expand All @@ -47,14 +59,14 @@ def get_team_scores(self, team, time, show_upcoming, use_12_hour_format):
time_frame = 'n' if show_upcoming else 'p'
if team_id:
try:
req = self._get('teams/{team_id}/fixtures?timeFrame={time_frame}{time}'.format(
req = self._get('teams/{team_id}/matches?timeFrame={time_frame}{time}'.format(
team_id=team_id, time_frame=time_frame, time=time))
team_scores = req.json()
if len(team_scores["fixtures"]) == 0:
if len(team_scores["matches"]) == 0:
click.secho("No action during past week. Change the time "
"parameter to get more fixtures.", fg="red", bold=True)
else:
self.writer.team_scores(team_scores, time, show_upcoming, use_12_hour_format)
self.writer.team_scores(team_scores, time)
except APIErrorException as e:
click.secho(e.args[0],
fg="red", bold=True)
Expand All @@ -66,7 +78,7 @@ def get_standings(self, league):
"""Queries the API and gets the standings for a particular league"""
league_id = self.league_ids[league]
try:
req = self._get('soccerseasons/{id}/leagueTable'.format(
req = self._get('competitions/{id}/standings'.format(
id=league_id))
self.writer.standings(req.json(), league)
except APIErrorException:
Expand All @@ -85,11 +97,11 @@ def get_league_scores(self, league, time, show_upcoming, use_12_hour_format):
if league:
try:
league_id = self.league_ids[league]
req = self._get('soccerseasons/{id}/fixtures?timeFrame={time_frame}{time}'.format(
req = self._get('competitions/{id}/matches?timeFrame={time_frame}{time}'.format(
id=league_id, time_frame=time_frame, time=str(time)))
fixtures_results = req.json()
# no fixtures in the past week. display a help message and return
if len(fixtures_results["fixtures"]) == 0:
if len(fixtures_results["matches"]) == 0:
click.secho("No {league} matches in the past week.".format(league=league),
fg="red", bold=True)
return
Expand All @@ -101,7 +113,7 @@ def get_league_scores(self, league, time, show_upcoming, use_12_hour_format):
else:
# When no league specified. Print all available in time frame.
try:
req = self._get('fixtures?timeFrame={time_frame}{time}'.format(
req = self._get('matches?timeFrame={time_frame}{time}'.format(
time_frame=time_frame, time=str(time)))
fixtures_results = req.json()
self.writer.league_scores(fixtures_results,
Expand All @@ -118,10 +130,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
Loading

0 comments on commit 7fdabcf

Please sign in to comment.