-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgold.py
37 lines (23 loc) · 762 Bytes
/
gold.py
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
27
28
29
30
31
32
33
34
35
36
import requests
from config import URL_GOLD
import json
def get_data(url):
response = requests.get(url)
if response.status_code == 200:
return json.loads(response.text)
return None
def get_gold(data):
return data['list']
def gold_coin(price_golds, value_gold=1):
return (price_golds * value_gold)
def import_data_to_file(currency, time):
list_currency = list()
for i in currency:
list_currency.append(f'{i["name"]}: {i["price"]}')
with open(f'archive/gold.json', 'w') as f:
f.writelines(json.dumps(list_currency))
json_data = get_data(URL_GOLD)
all_gold = get_gold(json_data)
timeUpdate = json_data['timeUpdate'][0]
price_gold = all_gold[0]['price']
import_data_to_file(all_gold, timeUpdate)