-
Notifications
You must be signed in to change notification settings - Fork 1
/
crawl_cron.py
67 lines (55 loc) · 2.07 KB
/
crawl_cron.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
62
63
64
65
66
67
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 18 15:35:12 2021
@author: maurer
"""
from entsoe import EntsoePandasClient
import pandas as pd
from entsoe_data.entsoe_crawler import EntsoeCrawler
from entsog_data.entsog_crawler import EntsogCrawler
def updateEntsoe(db, api_key, first=False):
try:
client = EntsoePandasClient(api_key=api_key)
crawler = EntsoeCrawler(database=db)
if first:
start = pd.Timestamp('20150101', tz='Europe/Berlin')
delta = pd.Timestamp.now(tz='Europe/Berlin')-start
crawler.create_database(client, start, delta)
crawler.update_database(client, start, delta)
else:
crawler.update_database(client)
except Exception as e:
print(f'Error in UpdateENTSOE: {e}')
def updateEntsog(db, first=False):
try:
crawler = EntsogCrawler(db)
names = ['cmpUnsuccessfulRequests',
# 'operationaldata',
# 'cmpUnavailables',
# 'cmpAuctions',
# 'AggregatedData', # operationaldata aggregated for each zone
# 'tariffssimulations',
# 'tariffsfulls',
# 'urgentmarketmessages',
'connectionpoints',
'operators',
'balancingzones',
'operatorpointdirections',
'Interconnections',
'aggregateInterconnections']
if first:
crawler.pullData(names)
indicators = ['Physical Flow', 'Allocation', 'Firm Technical']
crawler.pullOperationalData(indicators)
except Exception as e:
print(f'Error in UpdateENTSOG: {e}')
if __name__ == '__main__':
import os
first = False
db = os.getenv('DATABASE_URI','postgresql://entso:entso@localhost:5432')
#from sqlalchemy import create_engine
#t = create_engine(f'{db}/entsoe')
api_key = os.getenv('ENTSOE_API_KEY', 'ae2ed060-c25c-4eea-8ae4-007712f95375')
updateEntsoe(f'{db}/entsoe', api_key, first=first)
updateEntsog(f'{db}/entsog', first=first)