Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating poznan source #3693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,51 @@ def fetch(self) -> list[Collection]:

soup = BeautifulSoup(r.text, "html.parser")

year = datetime.date.today().year
month = datetime.date.today().month
# Find all dates with available scheduling
date_selector_wrapper = soup.find("div", id="month_selector_0_wrapper")
if not isinstance(date_selector_wrapper, Tag):
raise Exception("Could not parse page with waste scheduling")

date_rows = date_selector_wrapper.find_all("div", {"class": "select_element"})
formatted_dates = [
date['value'] for date in date_rows if isinstance(date, Tag)
]

table = soup.find("table", id="schedule_0")
if not isinstance(table, Tag):
raise Exception("Invalid address")

year = datetime.date.today().year
month = datetime.date.today().month
formatted_date = f"{month}.{year}"

# find all non empty tr's
trs = [
tr for tr in table.find_all("tr") if isinstance(tr, Tag) and tr.find_all()
]
entries = []

for row in trs[1:]: # Skipping first row since it is a header
all_cells = row.find_all("td")
collection_name = all_cells[0].text.strip()
# iterate over all rows with dates without collection name
for cell in all_cells[1:]:
if (
not isinstance(cell, Tag)
or not cell["data-value"] == formatted_date
or not cell.text.strip()
):
continue

for day in cell.text.split(","):
day = day.strip()
entries.append(
Collection(
datetime.date(year, month, int(day)),
collection_name,
ICON_MAP.get(collection_name, "mdi:recycle"),
for formatted_date in formatted_dates:
date = datetime.datetime.strptime(formatted_date, '%m.%Y').date()
year = date.year
month = date.month

# find all non empty tr's
trs = [
tr for tr in table.find_all("tr") if isinstance(tr, Tag) and tr.find_all()
]

for row in trs[1:]: # Skipping first row since it is a header
all_cells = row.find_all("td")
collection_name = all_cells[0].text.strip()
# iterate over all rows with dates without collection name
for cell in all_cells[1:]:
if (
not isinstance(cell, Tag)
or not cell["data-value"] == formatted_date
or not cell.text.strip()
):
continue

for day in cell.text.split(","):
day = day.strip()
entries.append(
Collection(
datetime.date(year, month, int(day)),
collection_name,
ICON_MAP.get(collection_name, "mdi:recycle"),
)
)
)

return entries
Loading