Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
Conflicts:
	fut14/__init__.py
	setup.py
  • Loading branch information
oczkers committed Jan 13, 2014
2 parents 308f8ed + cd46658 commit 320ac43
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Patches and Suggestions
- mvillarejo
- Mauro Marano
- John Nurseri <in.nursery@gmail.com>
- Innursery
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Usage
>>> fut.tradepileDelete(trade_id) # removes item from tradepile
>>> fut.watchlistDelete(trade_id) # removes item from watch list
>>> fut.keepalive() # send keepalive ping to avoid timeout
>>> fut.keepalive() # send keepalive ping to avoid timeout (send at least one request every ~10 minutes)
to be continued ;-)
...
Expand Down
2 changes: 1 addition & 1 deletion fut14/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

__title__ = 'fut14'
__version__ = '0.0.6'
__version__ = '0.0.7'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down
37 changes: 30 additions & 7 deletions fut14/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

from .config import headers
from .urls import urls
from .exceptions import Fut14Error
from .exceptions import (Fut14Error, ExpiredSession, InternalServerError,
UnknownError, PermissionDenied)
from .EAHashingAlgorithm import EAHashingAlgorithm


Expand Down Expand Up @@ -88,15 +89,16 @@ def __init__(self, email, passwd, secret_answer, platform='pc', debug=False):
self.passwd = passwd
self.secret_answer_hash = EAHashingAlgorithm().EAHash(secret_answer)
self.platform = platform
self.urls = urls(platform)
self.r = requests.Session() # init/reset requests session object
self.r.headers = headers # i'm chrome browser now ;-)
self.credits = 0
self.__login__(self.email, self.passwd, self.secret_answer_hash)

def __login__(self, email, passwd, secret_answer_hash):
"""Just log in."""
# TODO: split into smaller methods
# create session
self.r = requests.Session() # init/reset requests session object
self.r.headers = headers # i'm chrome browser now ;-)
self.urls = urls(self.platform)
# === login
self.urls['login'] = self.r.get(self.urls['fut_home']).url
self.r.headers['Referer'] = self.urls['main_site'] # prepare headers
Expand All @@ -117,7 +119,7 @@ def __login__(self, email, passwd, secret_answer_hash):
if self.debug: open('fut14.log', 'wb').write(rc.content)
rc = rc.text
if 'EASW_ID' not in rc:
raise Fut14Error('Invalid email or password.')
raise Fut14Error('Error during login process (probably invalid email or password).')
self.nucleus_id = re.search("var EASW_ID = '([0-9]+)';", rc).group(1)
#self.urls['fut_base'] = re.search("var BASE_FUT_URL = '(https://.+?)';", rc).group(1)
#self.urls['fut_home'] = re.search("var GUEST_APP_URI = '(http://.+?)';", rc).group(1)
Expand Down Expand Up @@ -211,12 +213,27 @@ def __request__(self, method, url, *args, **kwargs):
# TODO: update credtis?
self.r.headers['X-HTTP-Method-Override'] = method.upper()
rc = self.r.post(url, *args, **kwargs)
if self.debug: open('fut14.log', 'wb').write(rc.content)
if self.debug: open('fut14.log', 'wb').write(rc.content) # DEBUG
if rc.text == '':
self.keepalive() # credits not avaible in response, manualy updating
rc = {}
else:
rc = rc.json()
self.credits = rc.get('credits', self.credits) # update credits
# update credits
if 'credits' not in rc:
self.keepalive() # credits not avaible in response, manualy updating
else:
self.credits = rc['credits']
# error control
if 'code' and 'reason' in rc: # error
if rc['reason'] == 'expired session':
raise ExpiredSession
elif rc.get('string') == 'Internal Server Error (ut)':
raise InternalServerError
elif rc.get('string') == 'Permission Denied':
raise PermissionDenied
else:
raise UnknownError(rc.__str__())
return rc

def __get__(self, url, *args, **kwargs):
Expand Down Expand Up @@ -313,6 +330,12 @@ def sell(self, item_id, bid, buy_now=0, duration=3600):
rc = self.__post__(self.urls['fut']['SearchAuctionsListItem'], data=json.dumps(data))
return rc['id']

def quickSell(self, resource_id):
"""Quick sell."""
params = {'resourceId': resource_id}
self.__delete__(self.urls['fut']['Item'], params=params) # returns nothing
return True

def watchlistDelete(self, trade_id):
"""Removes card from watchlist."""
params = {'tradeId': trade_id}
Expand Down
14 changes: 14 additions & 0 deletions fut14/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@
class Fut14Error(RuntimeError):
"""There was an ambiguous exception that occurred while handling
your request."""

class UnknownError(Fut14Error):
"""Unknown error, please report full log at
https://github.com/oczkers/fut14/issues/24"""

class ExpiredSession(Fut14Error):
"""Session has expired,
you should send at least one request every ~10 minutes."""

class InternalServerError(Fut14Error):
"""[500] Internal Server Error (ut). (invalid parameters?)"""

class PermissionDenied(Fut14Error):
"""[461] Permission Denied. (outbid?)"""
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__ = 'fut14'
__version__ = '0.0.6'
__version__ = '0.0.7'
__author__ = 'Piotr Staroszczyk'
__author_email__ = 'piotr.staroszczyk@get24.org'
__license__ = 'GNU GPL v3'
Expand Down

0 comments on commit 320ac43

Please sign in to comment.