detect unknown remaining time

This commit is contained in:
mcinj 2022-04-23 16:24:56 -04:00
parent 38ba622464
commit 6e0474b7ed

View file

@ -74,7 +74,7 @@ class SteamGifts:
if not string_time: if not string_time:
logger.error(f"Could not determine time from string {string_time}") logger.error(f"Could not determine time from string {string_time}")
return None return None
match = re.search('(?P<number>[0-9]+) (?P<time_unit>(hour|day|minute|second))', string_time) match = re.search('(?P<number>[0-9]+) (?P<time_unit>(hour|day|minute|second|week))', string_time)
if match: if match:
number = int(match.group('number')) number = int(match.group('number'))
time_unit = match.group('time_unit') time_unit = match.group('time_unit')
@ -86,7 +86,10 @@ class SteamGifts:
return number return number
elif time_unit == 'second': elif time_unit == 'second':
return 1 return 1
elif time_unit == 'week':
return number * 7 * 24 * 60
else: else:
logger.error(f"Unkown time unit displayed in giveaway: {string_time}")
return None return None
else: else:
return None return None
@ -136,8 +139,12 @@ class SteamGifts:
times = item.select('div span[data-timestamp]') times = item.select('div span[data-timestamp]')
game_remaining = times[0].text game_remaining = times[0].text
game_remaining_in_minutes = self.determine_time_in_minutes(game_remaining) game_remaining_in_minutes = self.determine_time_in_minutes(game_remaining)
if game_remaining_in_minutes is None:
continue
game_created = times[1].text game_created = times[1].text
game_created_in_minutes = self.determine_time_in_minutes(game_created) game_created_in_minutes = self.determine_time_in_minutes(game_created)
if game_created_in_minutes is None:
continue
game_entries = int(item.select('div.giveaway__links span')[0].text.split(' ')[0].replace(',' ,'')) game_entries = int(item.select('div.giveaway__links span')[0].text.split(' ')[0].replace(',' ,''))
txt = f"{game_name} {game_cost} - {game_entries} - Created {game_created} ago with {game_remaining} remaining." txt = f"{game_name} {game_cost} - {game_entries} - Created {game_created} ago with {game_remaining} remaining."