-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateThread.py
More file actions
26 lines (21 loc) · 871 Bytes
/
UpdateThread.py
File metadata and controls
26 lines (21 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import threading
import time
from datetime import datetime
import requests
import sys
from currencies import currencies
class UpdateThread(threading.Thread):
def run(self) -> None:
super().run()
while True:
message = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S") + ':'
try:
for currency in currencies:
r = requests.get('http://www.nbrb.by/API/ExRates/Rates/' + str(currency.bank_code)).json()
currency.amount = r['Cur_OfficialRate'] / r['Cur_Scale']
message += '\n' + currency.name + ': ' + str(currency.amount) + currency.suf
print(message)
except:
print(message + '\nНе получайтся спарсить курсы валют!')
sys.exit()
time.sleep(3600)