PEP8ing whitespace

This commit is contained in:
Christopher Teutsch 2019-06-21 22:16:16 +02:00
parent 1eec302ad8
commit add06ef20d
Signed by: iwonder
GPG Key ID: 0EE33D788D50130D
2 changed files with 18 additions and 1 deletions

View File

@ -66,6 +66,7 @@ vals_group.add_argument(
nargs='?'
)
def _process_stdin(argv: str, res: utils.CurrencyResult) -> None:
argv = argv.split()
try:
@ -123,6 +124,7 @@ d | date: Print the date which the data is from.
except ValueError:
print("The currency specified does not exist.")
def is_float(string: str) -> bool:
try:
float(string)
@ -130,9 +132,11 @@ def is_float(string: str) -> bool:
except ValueError:
return False
def _parse_date_from_args(date_str: str) -> DTDate:
return DTDateTime.strptime(date_str).date()
def calc_result(amt: float, rate: utils.Rate, direction: int, duty: float = 0) -> float:
if direction == DIRECTION_FROM_EUR:
result = amt * rate.ask / 1+duty
@ -142,6 +146,7 @@ def calc_result(amt: float, rate: utils.Rate, direction: int, duty: float = 0) -
raise ValueError('direction must be DIRECTION_FROM_EUR or DIRECTION_TO_EUR')
return result
def fmt_and_calc(amt: float, cur: str, res: utils.CurrencyResult, direction: str) -> str:
cur = cur.upper()
if cur in res.rates:

View File

@ -19,12 +19,14 @@ Rate = namedtuple('Rate', ['abbr', 'full_name', 'ask', 'bid'])
CARD_MASTERCARD = ['0']
CARD_VISA = ['1']
class CurrencyResult():
class CurrencyResult:
def __init__(self):
self.rates = list()
self.card_type = str()
self.date = None
def _parse_rate(text: str) -> float or None:
if re.match('Keine Kursdaten vorhanden', text):
_r = None
@ -37,17 +39,20 @@ def _parse_rate(text: str) -> float or None:
_r = None
return _r
def _parse_card_type(text: str) -> str:
# Method for validating metadata from the PDF against the request data
text = text.split(':')[1]
text = text.strip('" ')
return text
def _parse_date(text: str) -> DTDate:
# Method for validating metadata from the PDF against the request data
text = text.split(': ')[1].rstrip()
return DTDateTime.strptime(text, '%d.%m.%Y').date()
def _array_remove_empty(obj: list) -> List[str]:
# just a macro for removing empty or empty-string array objects
try:
@ -57,6 +62,7 @@ def _array_remove_empty(obj: list) -> List[str]:
return obj
return obj
def _parse_line(line: str) -> Rate or None:
arr = line.split(" ") # 3 spaces = minimum separation in PDF
arr = _array_remove_empty(arr)
@ -97,6 +103,7 @@ def get_results_from_text(text: str, currency: str = None) -> CurrencyResult:
result.rates = rates
return result
def get_results_from_pdf(buf: BinaryIO or str, currency: str = None) -> CurrencyResult:
print('Parsing data... ', end='')
reader = PyPDF3.PdfFileReader(buf)
@ -105,6 +112,8 @@ def get_results_from_pdf(buf: BinaryIO or str, currency: str = None) -> Currency
text += reader.getPage(num).extractText()
print('Done.')
return get_results_from_text(text, currency=currency)
def get_fileio(date: DTDate, card_type: List[str] = CARD_VISA) -> BinaryIO: # pylint: disable=dangerous-default-value
# pylint: disable=no-member # mechanize.Browser has some lazy-loading methods that pylint doesn't see
print('Downloading rates for ' + date.strftime('%Y-%m-%d') + '... ', end='')
@ -134,6 +143,8 @@ def get_fileio(date: DTDate, card_type: List[str] = CARD_VISA) -> BinaryIO: # py
print(' Done.')
# Returns an open file-like object with the PDF as contents
return open(rp[0], 'rb')
def get_date() -> DTDate:
# For Sunday and Monday, use Friday's data; Saturday and Sunday are completely null
if DTDate.today().weekday() in [6, 0]:
@ -143,6 +154,7 @@ def get_date() -> DTDate:
date = DTDate.today() - DTTimeDelta(1)
return date
def mk_filename(date: DTDate, card_type: List[str]) -> str:
# List[str] is used because I don't want to make a class for just this
if card_type == CARD_MASTERCARD: