Skip to content

Commit d7d489e

Browse files
committed
fix import error if using setup.py install
1 parent c7fa2ea commit d7d489e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

soccer/jsonhandler.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import json
3+
4+
def load_json(file):
5+
"""Load JSON file at app start"""
6+
here = os.path.dirname(os.path.abspath(__file__))
7+
with open(os.path.join(here, file)) as jfile:
8+
data = json.load(jfile)
9+
return data
10+
11+
TEAM_DATA = load_json("teams.json")["teams"]
12+
TEAM_NAMES = {team["code"]: team["id"] for team in TEAM_DATA}
13+
LEAGUE_DATA = load_json("leagues.json")["leagues"]
14+
LEAGUE_IDS = {league["code"]: league["id"] for league in LEAGUE_DATA}
15+
LEAGUE_PROPERTIES = {league["code"]: league["properties"] for league in LEAGUE_DATA if league["properties"] != "null"}

soccer/main.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22
import os
33
import requests
44
import sys
5-
import json
65

76

87
from soccer.exceptions import IncorrectParametersException, APIErrorException
98
from soccer.writers import get_writer
9+
from soccer.jsonhandler import TEAM_NAMES, LEAGUE_IDS, LEAGUE_PROPERTIES
1010

1111

1212
BASE_URL = 'http://api.football-data.org/alpha/'
1313
LIVE_URL = 'http://soccer-cli.appspot.com/'
1414

1515

16-
def load_json(file):
17-
"""Load JSON file at app start"""
18-
here = os.path.dirname(os.path.abspath(__file__))
19-
with open(os.path.join(here, file)) as jfile:
20-
data = json.load(jfile)
21-
return data
22-
23-
24-
TEAM_DATA = load_json("teams.json")["teams"]
25-
TEAM_NAMES = {team["code"]: team["id"] for team in TEAM_DATA}
26-
LEAGUE_DATA = load_json("leagues.json")["leagues"]
27-
LEAGUE_IDS = {league["code"]: league["id"] for league in LEAGUE_DATA}
28-
LEAGUE_PROPERTIES = {league["code"]: league["properties"] for league in LEAGUE_DATA if league["properties"] != "null"}
29-
3016

3117
def get_input_key():
3218
"""Input API key and validate"""

soccer/writers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from itertools import groupby
99
from collections import namedtuple
1010

11-
from soccer.main import LEAGUE_IDS, LEAGUE_PROPERTIES
11+
from soccer.jsonhandler import LEAGUE_IDS, LEAGUE_PROPERTIES
1212

1313

1414
def get_writer(output_format='stdout', output_file=None):

0 commit comments

Comments
 (0)