-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Changes from 4 commits
31f15e6
8dbb782
b82e61d
d578143
632b2e4
a2ab1b5
b1635ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ nosetests.xml | |
.project | ||
.pydevproject | ||
.env | ||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import re | ||
from datetime import datetime, date | ||
|
||
import requests | ||
|
||
from datetime import datetime, date | ||
|
||
|
||
__all__ = ('FioBank',) | ||
|
||
|
@@ -26,6 +26,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/' | ||
|
@@ -79,6 +87,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: | ||
|
@@ -104,7 +115,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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this placement? I tend to cluster imports from std lib together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might only my thing but I usually do imports in following way:
import ...
from libs import ... - libs like django etc.
from core import ... - project modules
Usually its nicer to look at because from ... import ... are much longer than simple imports... But overall it does not matter, its just my kind of fetish :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I suppose, this is a clash of two fetishes :-( And I am the evil admin of this repo, so please obey, muhahaha! ;-)