Skip to content

Commit

Permalink
Read wind and solar values from print page (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorrieq authored and corradio committed Jul 31, 2018
1 parent d9c34fe commit d999fbd
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions parsers/IN_GJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .lib.validation import validate
from logging import getLogger

SLDCGUJ_URL = 'http://www.sldcguj.com/RealTimeData/PrintPage.php?page=realtimedemand.php'

station_map = {
"coal": ["Ukai(1-5)+Ukai6",
Expand Down Expand Up @@ -59,29 +60,23 @@ def fetch_data(zone_key, session=None, logger=None):
values = collections.Counter()
zonekey.assert_zone_key(zone_key, 'IN-GJ')

solar_html = web.get_response_soup(
zone_key, 'https://www.sldcguj.com/RealTimeData/GujSolar.php', session)
wind_html = web.get_response_soup(
zone_key, 'https://www.sldcguj.com/RealTimeData/wind.php', session)

values['date'] = arrow.get(
solar_html.find_all('tr')[0].text.split('\t')[-1].strip()
+ ' Asia/Kolkata', 'D-MM-YYYY H:mm:ss ZZZ').datetime
values['solar'] = split_and_sum(
solar_html.find_all('tr')[-1].find_all('td')[-1].text.strip())
values['wind'] = split_and_sum(
wind_html.find_all('tr')[-1].find_all('td')[-1].text.strip())

cookies_params = {
'ASPSESSIONIDSUQQQTRD': 'ODMNNHADJFGCMLFFGFEMOGBL',
'PHPSESSID': 'a301jk6p1p8d50dduflceeg6l1'
}

rows = web.get_response_soup(
zone_key,
'http://www.sldcguj.com/RealTimeData/PrintPage.php?page=realtimedemand.php',
session).find_all('tr')
soup = web.get_response_soup(zone_key, SLDCGUJ_URL, session)
rows = soup.find_all('tr')
cells = [c.text.strip() for c in soup.find_all('td')]

# get wind and solar values
values['date'] = arrow.get(cells[1], 'DD-MM-YYYY HH:mm:ss').replace(
tzinfo='Asia/Kolkata')
[wind_solar_index] = [i for i, c in enumerate(cells) if c == '(Wind+Solar) Generation']
value = cells[wind_solar_index + 1]
values['wind'], values['solar'] = [int(v) for v in value.split(' + ')]

# get other production values
for row in rows:
elements = row.find_all('td')
if len(elements) > 3: # will find production rows
Expand Down Expand Up @@ -177,7 +172,7 @@ def fetch_production(zone_key='IN-GJ', session=None, target_datetime=None,

data = {
'zoneKey': zone_key,
'datetime': value_map['date'],
'datetime': value_map['date'].datetime,
'production': {
'biomass': None,
'coal': value_map.get('coal', 0),
Expand Down

0 comments on commit d999fbd

Please sign in to comment.