Advertisement
Guest User

Untitled

a guest
Apr 15th, 2023
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import requests
  2. import json
  3. import datetime
  4.  
  5. current_cost = 0
  6. cost_history = dict()
  7. history_index = 0
  8. cost_string = "Cena (EUR/MWh)"
  9. hour_string = "Hodina"
  10. cost_data = "https://www.ote-cr.cz/cs/kratkodobe-trhy/elektrina/denni-trh/@@chart-data"
  11.  
  12. date = datetime.datetime.now()
  13. params = dict (
  14.     date = date.strftime('%Y-%m-%d')
  15. )
  16.  
  17. response = requests.get(url=cost_data, params=params)
  18. json = response.json()
  19. cost_axis = ""
  20. hour_axis = ""
  21. for key in json['axis'].keys():
  22.     if json['axis'][key]['legend'] == cost_string:
  23.         cost_axis = key
  24.     if json['axis'][key]['legend'] == hour_string:
  25.         hour_axis = key
  26.  
  27.  
  28. for values in json['data']['dataLine']:
  29.     if values['title'] == cost_string:
  30.         for data in values['point']:
  31.            history_index = int(data[hour_axis])-1
  32.            cost_history[history_index] = float(data[cost_axis])
  33.         current_cost = cost_history[date.hour]
  34.  
  35. print(current_cost)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement