Skip to content

Commit

Permalink
Correct TR.fetch_price arguments (#1410)
Browse files Browse the repository at this point in the history
* Add optional zone_key, session, target_datetime and logger args

* This makes it compatible with the backend feeder
  • Loading branch information
lorrieq authored and corradio committed May 14, 2018
1 parent 3d71ded commit db31d32
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions parsers/TR.py
Expand Up @@ -4,8 +4,10 @@
import re
import json
import arrow
import logging
from bs4 import BeautifulSoup
import datetime as dt
from .lib import zonekey

SEARCH_DATA = re.compile(r'var gunlukUretimEgrisiData = (?P<data>.*);')
TIMEZONE = 'Europe/Istanbul'
Expand Down Expand Up @@ -59,8 +61,16 @@ def get_last_data_idx(productions):
return len(productions) - 1 # full day


def fetch_price():
soup = BeautifulSoup(requests.get(PRICE_URL).text, 'html.parser')
def fetch_price(zone_key='TR', session=None, target_datetime=None,
logger=logging.getLogger(__name__)):
if target_datetime:
raise NotImplementedError(
'This parser is not yet able to parse past dates')

zonekey.assert_zone_key(zone_key, 'TR')

r = session or requests.session()
soup = BeautifulSoup(r.get(PRICE_URL).text, 'html.parser')
cells = soup.select('.TexAlCenter')

# data is in td elements with class "TexAlCenter" and role "gridcell"
Expand Down

0 comments on commit db31d32

Please sign in to comment.