Prices 2023 added
This commit is contained in:
46
frankenergy.py
Normal file
46
frankenergy.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
import csv
|
||||
|
||||
def FrankEnergy():
|
||||
now = datetime.now()
|
||||
|
||||
yesterday = datetime.now() + timedelta(days=-1)
|
||||
startdate = yesterday.strftime("%Y-%m-%d")
|
||||
enddate = now.strftime("%Y-%m-%d")
|
||||
|
||||
if int(now.strftime("%H")) > 15:
|
||||
tomorrow = datetime.now() + timedelta(days=2)
|
||||
startdate = now.strftime("%Y-%m-%d")
|
||||
enddate = tomorrow.strftime("%Y-%m-%d")
|
||||
|
||||
headers = { "content-type":"application/json" }
|
||||
|
||||
query = f"""query MarketPrices {{
|
||||
marketPricesGas(startDate: "{startdate}", endDate: "{enddate}") {{
|
||||
from
|
||||
till
|
||||
marketPrice
|
||||
priceIncludingMarkup
|
||||
}}
|
||||
}}"""
|
||||
|
||||
response = requests.post('https://graphcdn.frankenergie.nl', json={'query': query}, headers=headers)
|
||||
data = response.json()
|
||||
|
||||
frank_gas_file = "frank_gas.csv"
|
||||
|
||||
frank_headers = ['till', 'from', 'marketPrice', 'priceIncludingMarkup']
|
||||
|
||||
with open(frank_gas_file, 'w') as csvfile:
|
||||
writer = csv.DictWriter(csvfile, fieldnames = frank_headers)
|
||||
writer.writeheader()
|
||||
writer.writerows(data['data']['marketPricesGas'])
|
||||
|
||||
for gas in data['data']['marketPricesGas']:
|
||||
print(gas['till'], gas['from'],gas['marketPrice'], gas['priceIncludingMarkup'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
FrankEnergy()
|
||||
|
||||
Reference in New Issue
Block a user