DAY'.upper()
input_period = input_period.split(' ')
print(input_period)
days = 0
seconds = 0
minutes = 0
hours = 0
time_dict = {
'SEC': exec('seconds = int(input_period[0])'),
'MIN': exec('minutes = int(input_period[0])'),
'HRS': exec('hours = int(input_period[0])'),
'DAY': exec('days = int(input_period[0])'),
'MTH': exec('days = int(input_period[0])*30'),
'YRS': exec('days = int(input_period[0])*365'),
}
if time_dict.get(input_period[1], True):
raise Exception
print(input_period[0])
input_period[1] = {'YRS':'MTH', 'MTH':'DAY', 'DAY':'HRS', 'HRS':'MIN', 'MIN':'SEC'}.get(input_period[1],input_period[1])
period = ''.join(input_period)
datetime_ = datetime.datetime.today() - datetime.timedelta(days=days, seconds=seconds, minutes=minutes, hours=hours,)
print(datetime_)
time_start = 'T'.join(str(datetime_).split(' ')).split('.')[0]
print(time_start)
url = f'https://rest.coinapi.io/v1/ohlcv/{method}/history?period_id={period}&time_start={time_start}'
print(url)
with open('request.txt', 'w') as f:
f.write('')
headers = {'X-CoinAPI-Key' : X_CoinAPI_Key}
data = requests.get(url, headers=headers)
with open('request.txt', 'a') as f:
for post in data:
f.write(post.decode())
with open('request.txt', 'r+') as f:
request = json.loads(f.read())
answer = [str({example['time_close']:example['price_close']})+'\n' for example in request ]
for i in answer:
print(i)
input()
ЧТо делает этот код?😕😐😳
Обсуждают сегодня