Now with a serious import module
back home
- datetime
# Run this using "asyncio"
async def main():
await micropip.install(["lxml","requests","pytz"])
# await micropip.install(["lxml","requests","pytz", "libreadline-gplv2-dev", "libncursesw5-dev", "libssl-dev", "libsqlite3-dev", "tk-dev", "libgdbm-dev", "libc6-dev", "libbz2-dev"])
await loop.run_until_complete(main())
from lxml import html
import requests
import datetime
import pytz
strCurrentDateTime = str(datetime.datetime.now(pytz.timezone('Europe/Berlin')))
strCurrentDate = strCurrentDateTime[0:10]
strCurrentTime = strCurrentDateTime[11:16]
print('Today is ',strCurrentDateTime, strCurrentDate, strCurrentTime)
# breakpoint()
urlToCapture = 'https://www.epexspot.com/en/market-data?market_area=DE&trading_date=&delivery_date=' \
+ strCurrentDate + '&underlying_year=&modality=Continuous&sub_modality=&product=15&data_mode=table&period='
page = requests.get(urlToCapture)
print('Server reply: ' + str(page))
tree = html.fromstring(page.content)
posOffset = 3 + 7*int(strCurrentTime[0:2])
# print(posOffset)
strMinutes = strCurrentTime[3:5]
if strMinutes >= "45":
posMinutes = 4
elif strMinutes >= "30":
posMinutes = 3
elif strMinutes >= "15":
posMinutes = 1
elif strMinutes >= "00":
posMinutes = 0
pos = posOffset + posMinutes
# print(pos)
xpathString = '//*[@id="epex-md-common-data-container"]/div/section/div[3]/div/div/div[2]/table/tbody/tr[' + str(pos) + ']/td[4]/text()'
spotprice = tree.xpath(xpathString)
print (spotprice[0])