/
IN_DL.py
87 lines (65 loc) · 2.47 KB
/
IN_DL.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
from requests import Session
from .lib import web
from .lib import zonekey
from .lib import IN
plants = {
"CCGT-Bawana": "Gas",
"DMSWSL-Dsidc": "G2E",
"EDWPL-Gazipur": "G2E",
"GT": "Gas",
"Pragati": "Gas",
"TOWMP-Okhla": "G2E"
}
def fetch_consumption(zone_key='IN-DL', session=None, target_datetime=None, logger=None):
"""Fetch Delhi consumption"""
if target_datetime:
raise NotImplementedError('This parser is not yet able to parse past dates')
zonekey.assert_zone_key(zone_key, 'IN-DL')
html = web.get_response_soup(zone_key, 'http://www.delhisldc.org/Redirect.aspx', session)
india_date_time = IN.read_datetime_from_span_id(html, 'DynamicData1_LblDate', 'DD-MMM-YYYY hh:mm:ss A')
demand_value = IN.read_value_from_span_id(html, 'DynamicData1_LblLoad')
data = {
'zoneKey': zone_key,
'datetime': india_date_time.datetime,
'consumption': demand_value,
'source': 'delhisldc.org'
}
return data
def fetch_production(zone_key='IN-DL', session=None, target_datetime=None, logger=None):
"""Fetch Delhi production"""
if target_datetime:
raise NotImplementedError('This parser is not yet able to parse past dates')
energy = {
"Gas": 0,
"G2E": 0,
"Coal": 0
}
zonekey.assert_zone_key(zone_key, 'IN-DL')
html = web.get_response_soup(zone_key, 'http://www.delhisldc.org/Redirect.aspx?Loc=0804', session)
india_date_string = IN.read_text_from_span_id(html, 'ContentPlaceHolder3_ddgenco')
india_date_time = IN.read_datetime_with_only_time(india_date_string, 'HH:mm:ss')
prod_table = html.find("table", {"id": "ContentPlaceHolder3_dgenco"})
prod_rows = prod_table.findAll('tr')
for plant in range(1, len(plants) + 1):
energy[plants[read_name(prod_rows[plant])]] += read_value(prod_rows[plant])
data = {
'zoneKey': zone_key,
'datetime': india_date_time.datetime,
'production': {
'coal': energy["Coal"],
'gas': energy["Gas"],
'biomass': energy["G2E"]
},
'source': 'delhisldc.org',
}
return data
def read_value(row, index=2):
value = float(row.findAll('td')[index].text)
return value if value >= 0.0 else 0.0
def read_name(row, index=0):
return row.findAll('td')[index].text
if __name__ == '__main__':
session = Session()
print(fetch_production('IN-DL', session))
print(fetch_consumption('IN-DL', session))