Skip to content

Commit fb82bd5

Browse files
committed
clean up dob calculator
1 parent c9f618f commit fb82bd5

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

scrapers/LadyboyGold/island_dollars.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,19 @@ def parse_set_as_scene(domain: str, cms_set: Any, cdn_servers: dict[str, Any]) -
161161

162162
return scene
163163

164-
def infer_birthday_from_age_and_born(age: int, born_str: str, added: datetime) -> str | None:
164+
def calculate_dob(age: int, born_str: str, added: datetime) -> str | None:
165165
try:
166-
born_date = datetime.strptime(born_str, "%B %d")
167-
current_year = datetime.now().year
168-
born_date = born_date.replace(year=current_year)
169-
added_date = datetime(current_year, added.month, added.day)
170-
if born_date > added_date:
171-
born_date = born_date.replace(year=current_year - 1)
172-
birth_year = born_date.year - age - (current_year - added.year)
173-
birth_date = born_date.replace(year=birth_year)
174-
return birth_date.strftime("%Y-%m-%d")
166+
birth_year = added.year - age
167+
birthday = datetime.strptime(born_str, "%B %d")
168+
169+
# check if birthday has occurred yet in added_date year
170+
birthday_in_added_year = datetime(added.year, birthday.month, birthday.day)
171+
172+
if added < birthday_in_added_year:
173+
birth_year -= 1
174+
175+
date_of_birth = birthday.replace(year=birth_year)
176+
return date_of_birth.strftime("%Y-%m-%d")
175177
except ValueError as e:
176178
log.error(f"Error parsing born date: {e}")
177179
return None
@@ -222,7 +224,7 @@ def parse_model_as_performer(domain: str, cms_data: Any, cdn_servers: dict[str,
222224
log.debug(f"added: {added}")
223225

224226
# object containing "value": "value": "May 25", extract born date
225-
if inferred_birthday := infer_birthday_from_age_and_born(int(age["value"]), born["value"], added):
227+
if inferred_birthday := calculate_dob(int(age["value"]), born["value"], added):
226228
performer["birthdate"] = inferred_birthday
227229

228230
if measurements := data_detail_values.get("6"):

0 commit comments

Comments
 (0)