Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttling error for http conflict, fixing Issue #5 #7

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ nosetests.xml
.project
.pydevproject
.env
.idea/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ Listing latest transactions:
>>> client.last(from_date='2013-03-01') # sets cursor to given date and returns following transactions
```

For further information [read code](https://github.com/honzajavorek/fiobank/blob/master/fiobank.py).
## Conflict error
[Fio API documentation](http://www.fio.cz/docs/cz/API_Bankovnictvi.pdf) (Section 8.2) states that a single token should be used only once per 30s. Otherwise a HTTP conflict will be returned and `Fiobank.ThrottlingError` will be raised.


For further information [read code](https://github.com/honzajavorek/fiobank/blob/master/fiobank.py).

## License: ISC

Expand Down
14 changes: 13 additions & 1 deletion fiobank.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests



__all__ = ('FioBank',)


Expand All @@ -26,6 +27,14 @@ def sanitize_value(value, convert=None):
return value


class ThrottlingError(Exception):
"""
Throttling error raised when api is being used too fast.
"""
def __str__(self):
return 'Token should be used only once per 30s.'


class FioBank(object):

base_url = 'https://www.fio.cz/ib_api/rest/'
Expand Down Expand Up @@ -79,6 +88,9 @@ def _request(self, action, **params):
url = template.format(token=self.token, **params)

response = requests.get(url)
if response.status_code == requests.codes['conflict']:
raise ThrottlingError()

response.raise_for_status()

if response.content:
Expand All @@ -104,7 +116,7 @@ def _parse_info(self, data):
def _parse_transactions(self, data):
schema = self.transaction_schema
try:
entries = data['accountStatement']['transactionList']['transaction']
entries = data['accountStatement']['transactionList']['transaction'] # noqa
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why noqa? if I'm looking right, it shouldn't be longer than 80 chars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's exactly 80, which is the problem since pep states that you should "Limit all lines to a maximum of 79 characters." https://www.python.org/dev/peps/pep-0008/#maximum-line-length

The code should be at most 79 chars meaning that it will always fit to 80 chars screen...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, approved. Splitting this into two lines just because of one char would be pretty much dumb :-) 👍

except TypeError:
entries = []

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
base_path = os.path.dirname(__file__)


version = '0.0.4'
version = '0.0.5'


# release a version, publish to GitHub and PyPI
Expand Down