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 4 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/
17 changes: 14 additions & 3 deletions fiobank.py
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
Copy link
Owner

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

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 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

Copy link
Owner

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! ;-)



__all__ = ('FioBank',)

Expand All @@ -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/'
Expand Down Expand Up @@ -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:
Expand All @@ -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
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