Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
oczkers committed Sep 17, 2015
2 parents 56ae6b0 + a51db40 commit 00f60c5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ Changelog
---------


0.0.23 (2015-02-11)
0.1.0 (2015-09-1?)
++++++++++++++++++
* fifa 16
* core: update credits only on demand
* config: update user-agent (chrome 45 @ win10)

0.0.24 (2015-02-11)
++++++++++++++++++
* core: fix #135 type conversion in quickSell & watchlistDelete
* core: rename parameter squad_num to squad_id

0.0.23 (2015-02-09)
++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion fut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

__title__ = 'fut'
__version__ = '0.0.24'
__version__ = '0.1.0'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down
4 changes: 2 additions & 2 deletions fut/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# chrome 33
# chrome 45 @ win10
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip,deflate,sdch',
'Accept-Language': 'en-US,en;q=0.8',
Expand Down
50 changes: 31 additions & 19 deletions fut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
# TODO: split into smaller methods
# TODO: check first if login is needed (https://www.easports.com/fifa/api/isUserLoggedIn)
secret_answer_hash = EAHashingAlgorithm().EAHash(secret_answer)
self.credits = 0
# create session
self.r = requests.Session() # init/reset requests session object
# load saved cookies/session
Expand All @@ -130,27 +129,35 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
self.r.headers = headers.copy() # i'm chrome browser now ;-)
self.urls = urls(platform)
# TODO: urls won't be loaded if we drop here
if platform == 'pc':
gameSku = 'FFA16PCC'
elif platform == 'xbox':
gameSku = 'FFA16XBO'
elif platform == 'ps3':
gameSku = 'FFA16PS3' # not tested
else:
raise FutError('Wrong platform. (Valid ones are pc/xbox/ps3)')
# if self.r.get(self.urls['main_site']+'/fifa/api/isUserLoggedIn').json()['isLoggedIn']:
# return True # no need to log in again
# emulate
if emulate == 'ios':
sku = 'FUT15IOS'
sku = 'FUT16IOS'
clientVersion = 11
elif emulate == 'and':
sku = 'FUT15AND'
sku = 'FUT16AND'
clientVersion = 11
# TODO: need more info about log in procedure in game
# elif emulate == 'xbox':
# sku = 'FFA15XBX' # FFA14CAP ?
# sku = 'FFA16XBX' # FFA14CAP ?
# clientVersion = 1
# elif emulate == 'ps3':
# sku = 'FFA15PS3' # FFA14KTL ?
# sku = 'FFA16PS3' # FFA14KTL ?
# clientVersion = 1
# elif emulate == 'pc':
# sku = '' # dunno
# clientVersion = 1
elif not emulate:
sku = 'FUT15WEB'
sku = 'FUT16WEB'
clientVersion = 1
else:
raise FutError('Invalid emulate parameter. (Valid ones are and/ios).') # pc/ps3/xbox/
Expand All @@ -161,8 +168,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
'password': passwd,
'_rememberMe': 'on',
'rememberMe': 'on',
'_eventId': 'submit',
'facebookAuth': ''}
'_eventId': 'submit'}
rc = self.r.post(self.urls['login'], data=data)
self.logger.debug(rc.content)

Expand All @@ -179,11 +185,16 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
if not code:
self.saveSession()
raise FutError('Error during login process - code is required.')
self.r.headers['Referer'] = rc.url
rc = self.r.post(rc.url, {'twoFactorCode': code, '_eventId': 'submit'}).text
self.r.headers['Referer'] = url = rc.url
# self.r.headers['Upgrade-Insecure-Requests'] = 1 # ?
# self.r.headers['Origin'] = 'https://signin.ea.com'
rc = self.r.post(url, {'twofactorCode': code, '_trustThisDevice': 'on', 'trustThisDevice': 'on', '_eventId': 'submit'}).text
if 'Incorrect code entered' in rc or 'Please enter a valid security code' in rc:
raise FutError('Error during login process - provided code is incorrect.')
self.logger.debug(rc)
if 'Set Up an App Authenticator' in rc:
rc = self.r.post(url.replace('s2', 's3'), {'_eventId': 'cancel', 'appDevice': 'IPHONE'}).text
self.logger.debug(rc)

self.r.headers['Referer'] = self.urls['login']
if self.r.get(self.urls['main_site'] + '/fifa/api/isUserLoggedIn').json()['isLoggedIn'] is not True: # TODO: parse error?
Expand Down Expand Up @@ -221,7 +232,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
self.persona_id = rc['personaId']
self.persona_name = rc['personaName']
self.clubs = [i for i in rc['userClubList']]
# sort clubs by lastAccessTime (latest firts)
# sort clubs by lastAccessTime (latest first)
self.clubs.sort(key=lambda i: i['lastAccessTime'], reverse=True)

# authorization
Expand All @@ -235,6 +246,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
# 'nuc': self.nucleus_id,
'nucleusPersonaId': self.persona_id,
'nucleusPersonaDisplayName': self.persona_name,
'gameSku': gameSku,
'nucleusPersonaPlatform': platform,
'locale': 'en-GB',
'method': 'authcode',
Expand Down Expand Up @@ -283,7 +295,8 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
del self.r.headers['X-UT-Route']
self.r.headers.update({
# 'X-HTTP-Method-Override': 'GET', # __request__ method manages this
'Referer': 'https://www.easports.com/iframe/fut15/bundles/futweb/web/flash/FifaUltimateTeam.swf',
'X-Requested-With': 'ShockwaveFlash/19.0.0.162',
'Referer': 'https://www.easports.com/iframe/fut16/bundles/futweb/web/flash/FifaUltimateTeam.swf',
'Origin': 'https://www.easports.com',
# 'Content-Type': 'application/json', # already set
'Accept': 'application/json',
Expand Down Expand Up @@ -316,7 +329,6 @@ def __request__(self, method, url, *args, **kwargs):
if not rc.ok: # status != 200
raise UnknownError(rc.content)
if rc.text == '':
self.keepalive() # credits not avaible in response, manualy updating
rc = {}
else:
captcha_token = rc.headers.get('Proxy-Authorization', '').replace('captcha=', '') # captcha token (always AAAA ?)
Expand All @@ -339,11 +351,6 @@ def __request__(self, method, url, *args, **kwargs):
raise FeatureDisabled
else:
raise UnknownError(rc.__str__())
# update credits
if 'credits' not in rc:
self.keepalive() # credits not avaible in response, manualy updating
else:
self.credits = rc['credits']
self.saveSession()
return rc

Expand Down Expand Up @@ -393,6 +400,11 @@ def logout(self, save=True):
self.saveSession()
return True

@property
def credits(self):
"""Returns credit amount."""
return self.__get__(self.urls['fut']['Credits'])['credits']

def saveSession(self):
'''Saves cookies/session.'''
if self.cookies_file:
Expand Down Expand Up @@ -576,7 +588,7 @@ def relist(self, clean=False):

def keepalive(self):
"""Just refresh credit amount to let know that we're still online. Returns credit amount."""
return self.__get__(self.urls['fut']['Credits'])
return self.credits

def pileSize(self):
"""Returns size of tradepile and watchlist."""
Expand Down
24 changes: 12 additions & 12 deletions fut/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def __updateUrls__(urls, cl):
urls['fut_config'] = '%s?cl=%s' % (urls['fut_config'], cl)
rc = xmltodict.parse(requests.get(urls['fut_config']).content)
services = rc['main']['services']['prod']
path = '{0}{1}game/fifa15/'.format(urls['fut_host'], rc['main']['directHttpServiceDestination'])
path_auth = '{0}/iframe/fut15{1}'.format(urls['main_site'], rc['main']['httpServiceDestination'])
path = '{0}{1}game/fifa16/'.format(urls['fut_host'], rc['main']['directHttpServiceDestination'])
path_auth = '{0}/iframe/fut16{1}'.format(urls['main_site'], rc['main']['httpServiceDestination'])
for i in services:
if i == 'authentication':
urls['fut'][i] = path_auth + services[i]
Expand All @@ -25,24 +25,24 @@ def urls(platform, cl=None):
"""Returns services urls."""
urls = {
'main_site': 'https://www.easports.com',
'futweb': 'https://www.easports.com/iframe/fut15/?baseShowoffUrl=https%3A%2F%2Fwww.easports.com%2Ffifa%2Fultimate-team%2Fweb-app%2Fshow-off&guest_app_uri=http%3A%2F%2Fwww.easports.com%2Ffifa%2Fultimate-team%2Fweb-app&locale=en_US',
'fut_config': 'https://www.easports.com/iframe/fut15/bundles/futweb/web/flash/xml/site_config.xml', # add timestamp
'futweb': 'https://www.easports.com/iframe/fut16/?baseShowoffUrl=https%3A%2F%2Fwww.easports.com%2Ffifa%2Fultimate-team%2Fweb-app%2Fshow-off&guest_app_uri=http%3A%2F%2Fwww.easports.com%2Ffifa%2Fultimate-team%2Fweb-app&locale=en_US',
'fut_config': 'https://www.easports.com/iframe/fut16/bundles/futweb/web/flash/xml/site_config.xml', # add timestamp
'fut_home': 'https://www.easports.com/uk/fifa/football-club/ultimate-team',
'fut': {}, # it's updated dynamicly (based on fut_config)
'fut_question': 'https://www.easports.com/iframe/fut15/p/ut/game/fifa15/phishing/question', # add timestamp
'fut_validate': 'https://www.easports.com/iframe/fut15/p/ut/game/fifa15/phishing/validate',
'fut_captcha_img': 'https://www.easports.com/iframe/fut15/p/ut/captcha/img', # add timestamp
'fut_captcha_validate': 'https://www.easports.com/iframe/fut15/p/ut/captcha/validate',
'fut_question': 'https://www.easports.com/iframe/fut16/p/ut/game/fifa16/phishing/question', # add timestamp
'fut_validate': 'https://www.easports.com/iframe/fut16/p/ut/game/fifa16/phishing/validate',
'fut_captcha_img': 'https://www.easports.com/iframe/fut16/p/ut/captcha/img', # add timestamp
'fut_captcha_validate': 'https://www.easports.com/iframe/fut16/p/ut/captcha/validate',

'fut_host': {'pc': 'https://utas.s2.fut.ea.com:443',
'ps3': 'https://utas.s2.fut.ea.com:443',
'xbox': 'https://utas.fut.ea.com:443',
'xbox': 'https://utas.s3.fut.ea.com:443',
'ios': 'https://utas.fut.ea.com:443',
'and': 'https://utas.fut.ea.com:443'},

'shards': 'https://www.easports.com/iframe/fut15/p/ut/shards', # add timestamp
'acc_info': 'https://www.easports.com/iframe/fut15/p/ut/game/fifa15/user/accountinfo',
'card_info': 'https://fifa15.content.easports.com/fifa/fltOnlineAssets/8D941B48-51BB-4B87-960A-06A61A62EBC0/2015/fut/items/web/',
'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://fifa15.content.easports.com/fifa/fltOnlineAssets/B488919F-23B5-497F-9FC0-CACFB38863D0/2016/fut/items/web/',
}
# urls['login'] = requests.get(urls['fut_home']).url

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


__title__ = 'fut'
__version__ = '0.0.24'
__version__ = '0.1.0'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down Expand Up @@ -58,6 +58,7 @@
# 'Programming Language :: Python :: 3.1', # not tested
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
# 'Programming Language :: Python :: 3.4', # not tested
# 'Programming Language :: Python :: Implementation :: CPython', # not tested
# 'Programming Language :: Python :: Implementation :: IronPython', # not tested
'Programming Language :: Python :: Implementation :: PyPy',
Expand Down

0 comments on commit 00f60c5

Please sign in to comment.