Skip to content

Commit

Permalink
nbsp, max 365 days back
Browse files Browse the repository at this point in the history
remove spaces
max 365 days back
  • Loading branch information
kudj committed Mar 11, 2024
1 parent 58dec41 commit 9a0360b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from requests_html import HTMLSession
from keboola.utils import parse_datetime_interval, split_dates_to_chunks
from keboola.csvwriter import ElasticDictWriter
import datetime


class Component(ComponentBase):
Expand All @@ -30,6 +31,11 @@ def run(self):
eshop_id = self.cfg.report_settings.eshop_id
date_from, date_to = parse_datetime_interval(self.cfg.report_settings.date_from,
self.cfg.report_settings.date_to)

if (datetime.datetime.now() - date_from).days > 365:
print("Cannot get data older than 1 year, downloading data for the last 365 days.")
date_from = datetime.datetime.now() - datetime.timedelta(days=365)

dates = split_dates_to_chunks(date_from, date_to, 0)

session = HTMLSession()
Expand Down Expand Up @@ -104,6 +110,7 @@ def get_stats_for_date(self, session, date, eshop_id):
if table_body:

values = [value.text.replace(\xa0\x8d', '').replace(' â\x82¬', '').replace('%', '')
.replace('Â', '').replace(' ', '').replace('&nbsp', '').replace(' ', '')
for value in table_body.find('tr')[0].find('td')]

row = {'eshop_id': eshop_id, 'date': date["start_date"]}
Expand Down

0 comments on commit 9a0360b

Please sign in to comment.