-
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.
Added getting currency data by dollar from api
- Loading branch information
Showing
5 changed files
with
63 additions
and
58 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,31 @@ | ||
import json | ||
|
||
import requests | ||
import datetime | ||
|
||
from features.currency.сurrency import Currency | ||
|
||
dollar_id = 145 | ||
date_format = "%Y-%m-%d" | ||
|
||
|
||
def fetch_currency_list(json_data): | ||
text = json.dumps(json_data, sort_keys=True, indent=4) | ||
print(text) | ||
|
||
return [Currency(**d) for d in json_data] | ||
|
||
|
||
def get_currency_response_json(): | ||
end_date = datetime.datetime.now().strftime(date_format) | ||
start_date = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime(date_format) | ||
|
||
parameters = { | ||
"startDate": start_date, | ||
"endDate": end_date | ||
} | ||
|
||
response = requests.get("http://www.nbrb.by/API/ExRates/Rates/Dynamics/{currency_id}".format(currency_id=dollar_id), | ||
params=parameters) | ||
|
||
return response.json() |
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,13 @@ | ||
from dataclasses import dataclass | ||
import datetime | ||
|
||
|
||
@dataclass | ||
class Currency: | ||
Cur_ID: int | ||
Cur_OfficialRate: float | ||
|
||
def __init__(self, Cur_ID, Date, Cur_OfficialRate, *args, **kwargs): | ||
self.Cur_ID = Cur_ID | ||
self.Date = datetime.datetime.strptime(Date, '%Y-%m-%dT%H:%M:%S') | ||
self.Cur_OfficialRate = Cur_OfficialRate |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
telebot==0.0.3 | ||
apiai==1.2.3 | ||
pyTelegramBotAPI==3.6.5 | ||
requests==2.20.0 | ||
pyowm==2.9.0 | ||
python-telegram-bot==10.1.0 | ||
pyTelegramBotAPI==3.6.6 | ||
requests==2.22.0 | ||
pyowm==2.10.0 | ||
python-telegram-bot==12.2.0 |
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 |
---|---|---|
@@ -1,53 +1,13 @@ | ||
class User: | ||
|
||
def __init__(self, last_name, first_name, username, user_id, lang, message): | ||
self._last_name = last_name | ||
self._first_name = first_name | ||
self._username = username | ||
self._user_id = user_id | ||
self._lang = lang | ||
self._message_text = message.text | ||
self._message = message | ||
|
||
def get_last_name(self): | ||
return self._last_name | ||
|
||
def get_first_name(self): | ||
return self._first_name | ||
|
||
def get_username(self): | ||
return self._username | ||
|
||
def get_user_id(self): | ||
return self._user_id | ||
|
||
def get_lang(self): | ||
return self._lang | ||
|
||
def get_message(self): | ||
return self._message | ||
|
||
def get_message_text(self): | ||
return self._message_text | ||
self.last_name = last_name | ||
self.first_name = first_name | ||
self.username = username | ||
self.user_id = user_id | ||
self.lang = lang | ||
self.message_text = message.text | ||
self.message = message | ||
|
||
def __repr__(self): | ||
return str(self.__dict__) | ||
|
||
|
||
class OnlyOne: | ||
class __OnlyOne: | ||
|
||
def __str__(self): | ||
return repr(self) | ||
instance = None | ||
|
||
def __init__(self): | ||
if not OnlyOne.instance: | ||
OnlyOne.instance = OnlyOne.__OnlyOne() | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.instance, name) | ||
|
||
def __setattr__(self, **kwargs): | ||
for key, value in kwargs.items(): | ||
setattr(self.instance, key, value) |