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 Jan 17, 2017
2 parents 99c37d3 + 3504e4e commit b9c9662
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
---------


0.2.7 (2017-01-17)
++++++++++++++++++
* fix missing import (#244)

0.2.6 (2017-01-10)
++++++++++++++++++
* add (minimum request) delay param (#233)
Expand Down
2 changes: 1 addition & 1 deletion fut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__title__ = 'fut'
__version__ = '0.2.6'
__version__ = '0.2.7'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down
20 changes: 13 additions & 7 deletions fut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import requests
import re
from time import time, sleep
import random
import time
try:
from cookielib import LWPCookieJar
except ImportError:
Expand Down Expand Up @@ -304,7 +305,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
'X-UT-Route': self.urls['fut_host'],
'Referer': self.urls['futweb'],
})
rc = self.r.get(self.urls['acc_info'], params={'_': int(time() * 1000)}, timeout=self.timeout)
rc = self.r.get(self.urls['acc_info'], params={'_': int(time.time() * 1000)}, timeout=self.timeout)
self.logger.debug(rc.content)
# pick persona (first valid for given game_sku)
personas = rc.json()['userAccountInfo']['personas']
Expand Down Expand Up @@ -356,7 +357,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
# validate (secret question)
self.r.headers['Accept'] = 'text/json' # prepare headers
del self.r.headers['Origin']
rc = self.r.get(self.urls['fut_question'], params={'_': int(time() * 1000)}, timeout=self.timeout)
rc = self.r.get(self.urls['fut_question'], params={'_': int(time.time() * 1000)}, timeout=self.timeout)
self.logger.debug(rc.content)
rc = rc.json()
if rc.get('string') != 'Already answered question.':
Expand Down Expand Up @@ -401,7 +402,7 @@ def __login__(self, email, passwd, secret_answer, platform='pc', code=None, emul
# """Returns shards info."""
# # TODO: headers
# self.r.headers['X-UT-Route'] = self.urls['fut_base']
# return self.r.get(self.urls['shards'], params={'_': int(time()*1000)}, timeout=self.timeout).json()
# return self.r.get(self.urls['shards'], params={'_': int(time.time()*1000)}, timeout=self.timeout).json()
# # self.r.headers['X-UT-Route'] = self.urls['fut_pc']

def __request__(self, method, url, *args, **kwargs):
Expand All @@ -413,8 +414,8 @@ def __request__(self, method, url, *args, **kwargs):
# TODO: update credtis?
self.r.headers['X-HTTP-Method-Override'] = method.upper()
self.logger.debug("request: {0} args={1}; kwargs={2}".format(url, args, kwargs))
sleep(max(self.request_time - time() + random.randrange(self.delay[0], self.delay[1]+1), 0)) # respect minimum delay
self.request_time = time() # save request time for delay calculations
time.sleep(max(self.request_time - time.time() + random.randrange(self.delay[0], self.delay[1]+1), 0)) # respect minimum delay
self.request_time = time.time() # save request time for delay calculations
rc = self.r.post(url, timeout=self.timeout, *args, **kwargs)
self.logger.debug("response: {0}".format(rc.content))
if not rc.ok: # status != 200
Expand All @@ -440,7 +441,7 @@ def __request__(self, method, url, *args, **kwargs):
elif err_code == '461' or err_string == 'Permission Denied':
raise PermissionDenied(err_code, err_reason, err_string)
elif err_code == '459' or err_string == 'Captcha Triggered':
# img = self.r.get(self.urls['fut_captcha_img'], params={'_': int(time()*1000), 'token': captcha_token}, timeout=self.timeout).content # doesnt work - check headers
# img = self.r.get(self.urls['fut_captcha_img'], params={'_': int(time.time()*1000), 'token': captcha_token}, timeout=self.timeout).content # doesnt work - check headers
img = None
raise Captcha(err_code, err_reason, err_string, captcha_token, img)
elif err_code == '401' or err_string == 'Unauthorized':
Expand Down Expand Up @@ -658,6 +659,11 @@ def club(self, count=10, level=10, type=1, start=0):
rc = self.__get__(self.urls['fut']['Club'], params=params)
return [itemParse({'itemData': i}) for i in rc['itemData']]

def clubConsumables(self):
"""Return all consumables."""
rc = self.__get__(self.urls['fut']['ClubConsumableSearch']) # or ClubConsumableStats?
return rc

def squad(self, squad_id=0):
"""Return a squad.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


__title__ = 'fut'
__version__ = '0.2.6'
__version__ = '0.2.7'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down

0 comments on commit b9c9662

Please sign in to comment.