-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 89fa357
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
data.csv | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
run: | ||
python calc.py | ||
install: | ||
pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from csv import DictReader | ||
from genericpath import exists | ||
from tabulate import tabulate | ||
from os.path import exists | ||
import sys | ||
import requests | ||
import time | ||
|
||
import html2text | ||
text_maker = html2text.HTML2Text() | ||
|
||
table = [['Дата', 'Значення', 'Валюта', 'Курс', 'Сумма']] | ||
total_income = 0 | ||
total_five_percent = 0 | ||
total_ten_percent = 0 | ||
if not exists('data.csv'): | ||
print('File data.csv does not exists') | ||
sys.exit() | ||
|
||
with open('data.csv') as read_obj: | ||
csv_dict_reader = DictReader(read_obj) | ||
|
||
for row in csv_dict_reader: | ||
date = row["date"] | ||
value = row['value'] | ||
currency = row['currency'] | ||
|
||
result = 0 | ||
currencyAmount = 0 | ||
if currency != 'UAH': | ||
response = requests.get( | ||
"https://bank.gov.ua/NBU_Exchange/exchange?date="+date+"&json") | ||
|
||
if response.text[0] == '<': | ||
print("Failed for date - "+date) | ||
print(text_maker.handle(response.text)) | ||
time.sleep(3) | ||
continue | ||
|
||
time.sleep(2) | ||
resJson = response.json() | ||
|
||
for x in resJson: | ||
if x["CurrencyCodeL"] == currency and currency != 'UAH': | ||
currencyAmount = x['Amount'] | ||
result = round(float(x["Amount"]) * float(value)) | ||
|
||
else: | ||
result = float(value) | ||
value = "" | ||
|
||
total_income += result | ||
|
||
table.append([date, value, currency, currencyAmount, | ||
"{:,.2f} UAH".format(result)]) | ||
|
||
total_five_percent = (total_income / 100) * 5 | ||
total_ten_percent = ((total_income - total_five_percent) / 100) * 10 | ||
|
||
print(tabulate(table, headers='firstrow', tablefmt='fancy_grid')) | ||
print(tabulate([["Total", "5%", "10%"], [total_income, total_five_percent, | ||
total_ten_percent]], headers='firstrow', tablefmt='fancy_grid')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
tabulate |