diff --git a/README.rst b/README.rst index b63e2e9..b18f9c9 100644 --- a/README.rst +++ b/README.rst @@ -136,6 +136,18 @@ Returns stats and definition IDs for each card variation. >>> fut.searchDefinition(asset_id, start=0, count=35) +Convert Team/League/Nation id to name +````````````` + +.. code-block:: python + + >>> fut.nations[1] + Albania + >>> fut.leagues[1] + Alka Superliga + >>> fut.teams[1] + Arsenal + Keepalive ````````````` Send keepalive ping (you have to make at least one request every ~10 minutes to avoid session expire/logout). diff --git a/fut/core.py b/fut/core.py index 70719df..237c6e4 100644 --- a/fut/core.py +++ b/fut/core.py @@ -95,6 +95,30 @@ def cardInfo(resource_id): return requests.get(url).json() ''' +# TODO: optimize messages, xml parser might be faster +def nations(): + rc = requests.get(urls('pc')['messages']).content + data = re.findall('\n (.+)', rc) + nations = {} + for i in data: + nations[int(i[0])] = i[1] + return nations + +def leagues(year=2016): + rc = requests.get(urls('pc')['messages']).content + data = re.findall('\n (.+)' % year, rc) + leagues = {} + for i in data: + leagues[int(i[0])] = i[1] + return leagues + +def teams(year=2016): + rc = requests.get(urls('pc')['messages']).content + data = re.findall('\n (.+)' % year, rc) + teams = {} + for i in data: + teams[int(i[0])] = i[1] + return teams class Core(object): def __init__(self, email, passwd, secret_answer, platform='pc', code=None, emulate=None, debug=False, cookies=cookies_file): @@ -406,6 +430,19 @@ def logout(self, save=True): self.saveSession() return True + # TODO: probably there is no need to refresh on every call? + @property + def nations(self): + return nations() + + @property + def leagues(self, year=2016): + return leagues(year) + + @property + def teams(self, year=2016): + return teams(year) + @property def credits(self): """Returns credit amount.""" diff --git a/fut/urls.py b/fut/urls.py index 575ce07..3c55bd8 100644 --- a/fut/urls.py +++ b/fut/urls.py @@ -45,6 +45,7 @@ def urls(platform, cl=None): 'shards': 'https://www.easports.com/iframe/fut16/p/ut/shards', # add timestamp 'acc_info': 'https://www.easports.com/iframe/fut16/p/ut/game/fifa16/user/accountinfo', 'card_info': 'https://fifa16.content.easports.com/fifa/fltOnlineAssets/B488919F-23B5-497F-9FC0-CACFB38863D0/2016/fut/items/web/', + 'messages': 'https://www.easports.com/iframe/fut16/bundles/futweb/web/flash/xml/localization/messages.en_GB.xml', # add cl } # urls['login'] = requests.get(urls['fut_home']).url