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

Release 2.1.7 #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog for pyaffalddk

## Version 2.1.7

**Date**: `2025-01-04`

### What's Changed

* Fixing Missing Material in Egedal Kommune. Closing [AffaldDK #221](https://github.com/briis/affalddk/issues/221)
* Added function to find a date based on Weekday and Odd or Even week. Closing [AffaldDK #226](https://github.com/briis/affalddk/issues/226)
* Bump `pyaffalddk` to V2.1.7

<details>
<summary><b>Previous Changes</b></summary>

## Version 2.1.6

**Date**: `2024-01-07`
Expand All @@ -11,9 +24,6 @@
* Fixing missing containers in Køge after renaming. Closing [AffaldDK #207](https://github.com/briis/affalddk/issues/207)
* Bump `pyaffalddk` to V2.1.6

<details>
<summary><b>Previous Changes</b></summary>

## Version 2.1.3

**Date**: `2024-01-05`
Expand Down
2 changes: 1 addition & 1 deletion pyaffalddk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
)

__title__ = "pyaffalddk"
__version__ = "2.1.6"
__version__ = "2.1.7"
__author__ = "briis"
__license__ = "MIT"
55 changes: 54 additions & 1 deletion pyaffalddk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
NAME_LIST,
NON_MATERIAL_LIST,
NON_SUPPORTED_ITEMS,
ODD_EVEN_ARRAY,
SUPPORTED_ITEMS,
WEEKDAYS,
)
Expand Down Expand Up @@ -443,7 +444,7 @@ async def get_pickup_data(self, address_id: str) -> PickupEvents:
data = await self._api.async_api_request(url, body)
result = json.loads(data["d"])
garbage_data = result["list"]
_LOGGER.debug("Garbage Data: %s", garbage_data)
# _LOGGER.debug("Garbage Data: %s", garbage_data)

for row in garbage_data:
if row["ordningnavn"] in NON_SUPPORTED_ITEMS:
Expand All @@ -454,11 +455,20 @@ async def get_pickup_data(self, address_id: str) -> PickupEvents:
_pickup_date = to_date(row["toemningsdato"])
elif str(row["toemningsdage"]).capitalize() in WEEKDAYS:
_pickup_date = get_next_weekday(row["toemningsdage"])
_LOGGER.debug("FOUND IN TOEMNINGSDAGE")
elif find_weekday_in_string(row["toemningsdage"]) != "None":
if row["toemningsdato"] not in NON_SUPPORTED_ITEMS:
_weekday = find_weekday_in_string(
row["toemningsdage"])
_pickup_date = get_next_weekday(_weekday)
elif find_odd_even_in_string(row["toemningsdage"]) != "None":
_weekday = find_weekday_in_string(
row["toemningsdage"])
_odd_even = find_odd_even_in_string(
row["toemningsdage"])
_LOGGER.debug("WEEK: %s - %s", _odd_even, _weekday)
_pickup_date = get_next_weekday_odd_even(
_weekday, _odd_even)
else:
_pickup_date = get_next_year_end()
else:
Expand Down Expand Up @@ -609,6 +619,7 @@ def get_garbage_type_from_material(


def get_next_weekday(weekday: str) -> dt.date:

weekdays = WEEKDAYS
current_weekday = dt.datetime.now().weekday()
target_weekday = weekdays.index(weekday.capitalize())
Expand All @@ -617,6 +628,39 @@ def get_next_weekday(weekday: str) -> dt.date:
return next_date.date()


def get_next_weekday_odd_even(weekday: str, odd_even: str) -> dt.date:
"""Get next date for a weekday considering odd/even weeks.

Args:
weekday: String with weekday name
odd_even: String with 'ulige' or 'lige' for odd/even weeks

Returns:
dt.date: Next date matching weekday and odd/even week criteria
"""
weekdays = WEEKDAYS
current_date = dt.datetime.now()
target_weekday = weekdays.index(weekday.capitalize())

# Find next occurrence of weekday
days_ahead = (target_weekday - current_date.weekday()) % 7
next_date = current_date + dt.timedelta(days=days_ahead)
if days_ahead == 0: # If today is the target weekday, move to next week
next_date += dt.timedelta(days=7)

# Check if week number matches odd/even criteria using ISO week numbers
week_number = next_date.isocalendar()[1]
_LOGGER.debug("Week Number: %s", week_number)
is_odd_week = week_number % 2 == 1
needs_odd = odd_even.lower() == 'ulige'

# If initial date doesn't match odd/even criteria, add a week
if is_odd_week != needs_odd:
next_date += dt.timedelta(days=7)

return next_date.date()


def list_to_string(list: list[str]) -> str:
"""Convert a list to a string."""
return " | ".join(list)
Expand All @@ -631,6 +675,15 @@ def find_weekday_in_string(text: str) -> str:
return "None"


def find_odd_even_in_string(text: str) -> str:
"""Loop through each word in a text string and compare with another word."""
words = text.split()
for w in words:
if w.lower() in ODD_EVEN_ARRAY:
return w.lower()
return "None"


def get_next_year_end() -> dt.date:
"""Return December 31 of the next year."""
today = dt.date.today()
Expand Down
7 changes: 6 additions & 1 deletion pyaffalddk/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"PP/MDK-plast 240 l (hver 2. uge) (1 stk.)",
"240 L. PMDK/PP 3 ugers tømning (1 stk.)",
"370 l Plast+MDK/Papir - Egenløsning (Privat) (1 stk.)",
"240 l Plast+MDK/Papir - Egenløsning (Privat) (1 stk.)",
],
"farligtaffald": [
"",
Expand Down Expand Up @@ -372,6 +373,7 @@
"4-kammer (370 l) (1 stk.)",
"Pap og papir/metal, glas og hård plast - 240 L (1 stk.)",
"240 l genbrug låg i låg (1 stk.)",
"Pap og papir/metal, glas og hård plast - 240 L (EX) (1 stk.)",
],
"madaffald": [
"140 L madaffald (1 stk.)",
Expand Down Expand Up @@ -528,5 +530,8 @@

MUNICIPALITIES_ARRAY = list(MUNICIPALITIES_LIST.keys())

WEEKDAYS = ["Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"]
ODD_EVEN_ARRAY = ["lige", "ulige"]

WEEKDAYS = ["Mandag", "Tirsdag", "Onsdag",
"Torsdag", "Fredag", "Lørdag", "Søndag"]
WEEKDAYS_SHORT = ["Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="pyaffalddk",
version="2.1.6",
version="2.1.7",
author="briis",
author_email="[email protected]",
description="Gets garbage collection data from danish Municipalities",
Expand Down