Created
May 27, 2021 18:19
-
-
Save adlerweb/b6b5fa17f7cbc7adac864ca19165be12 to your computer and use it in GitHub Desktop.
Fetch predicted renewable energy generation for Germany and find time of day where appliances would theoretically run with lowest environmental impact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import urllib.request | |
import json | |
weeknr = datetime.date.today().strftime("%V") | |
year = datetime.date.today().strftime("%Y") | |
url = "https://energy-charts.info/charts/power/data/de/week_"+year+"_"+weeknr+".json" | |
data = urllib.request.urlopen(url).read() | |
data = json.loads(data) | |
odata = [] | |
max = [0,0] | |
for section in data: | |
if 'xAxisValues' in section: | |
for xv in section['xAxisValues']: | |
odata.append([datetime.datetime.fromtimestamp(xv/1000)]) | |
if 'name' in section and 'data' in section and len(section['name']) > 0 and 'en' in section['name'][0] and section['name'][0]['en'] == 'Renewable Share forecast': | |
i = 0 | |
for xv in section['data']: | |
if xv is not None: | |
odata[i].append(xv) | |
if xv > max[1]: | |
max = [odata[i][0], xv] | |
i = i + 1 | |
print("Prefered load time: " + max[0].strftime("%Y-%m-%d_%H:%M") + " with " + str(max[1]) + "% Renewables") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not take in account load profiles (aka: is there any surplus or not) or CO² (aka: nuclear power)