-
Notifications
You must be signed in to change notification settings - Fork 3
/
elpriserV2.py
61 lines (42 loc) · 1.5 KB
/
elpriserV2.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from matplotlib import pyplot as plt
import time
from selenium import webdriver
import pandas as pd
import numpy as np
browser = webdriver.Firefox()
browser.get("https://www.nordpoolgroup.com/Market-data1/Dayahead/Area-Prices/ALL1/Hourly/")
time.sleep(3)
todays_file_name = browser.find_element_by_css_selector("#datatable > thead:nth-child(1) > tr:nth-child(1) > th:nth-child(1)").text
with open(str(todays_file_name) + ".csv", "w") as f:
f.write("hours,price\n")
i = 1
while i <= 24:
price = browser.find_element_by_css_selector("tr.data-row:nth-child(" + str(i) + ") > td:nth-child(9)").text.replace(",", ".")
if i == 23:
f.write(str(i-1))
f.write(",")
price = float(price)*7.5
price = float(price)/10
f.write(str(price))
break
price = float(price)*7.5
price = float(price)/10
print(price)
f.write(str(i-1))
f.write(",")
f.write(str(price))
f.write("\n")
i += 1
browser.close()
print("Data gathered, closing browser...")
data = pd.read_csv(todays_file_name + ".csv")
plt.figure(figsize=(10, 5))
plt.plot(data.hours, data.price)
plt.xticks(np.arange(min(data.hours), max(data.hours)+2, 1.0))
plt.yticks(np.arange(min(data.price), max(data.price)+1, 2.0))
plt.title("Electricity price per hour")
plt.xlabel("Time (in hours)")
plt.ylabel("Price (in 1/100th DKK per kWh)")
print("Program done!")
plt.show()
print("Exiting!")