Skip to content

Commit

Permalink
add nations, leagues, teams dicts, fix #79
Browse files Browse the repository at this point in the history
  • Loading branch information
oczkers committed Sep 24, 2015
1 parent 0d7c4f0 commit e2ae589
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
37 changes: 37 additions & 0 deletions fut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<trans-unit resname="search.nationName.nation([0-9]+)">\n <source>(.+)</source>', 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('<trans-unit resname="global.leagueFull.%s.league([0-9]+)">\n <source>(.+)</source>' % 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('<trans-unit resname="global.teamFull.%s.team([0-9]+)">\n <source>(.+)</source>' % 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):
Expand Down Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions fut/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e2ae589

Please sign in to comment.