Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import datetime
- current_cost = 0
- cost_history = dict()
- history_index = 0
- cost_string = "Cena (EUR/MWh)"
- hour_string = "Hodina"
- cost_data = "https://www.ote-cr.cz/cs/kratkodobe-trhy/elektrina/denni-trh/@@chart-data"
- date = datetime.datetime.now()
- params = dict (
- date = date.strftime('%Y-%m-%d')
- )
- response = requests.get(url=cost_data, params=params)
- json = response.json()
- cost_axis = ""
- hour_axis = ""
- for key in json['axis'].keys():
- if json['axis'][key]['legend'] == cost_string:
- cost_axis = key
- if json['axis'][key]['legend'] == hour_string:
- hour_axis = key
- for values in json['data']['dataLine']:
- if values['title'] == cost_string:
- for data in values['point']:
- history_index = int(data[hour_axis])-1
- cost_history[history_index] = float(data[cost_axis])
- current_cost = cost_history[date.hour]
- print(current_cost)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement