From fd0c309f7f89ac12bcf666fae4bcc2c4c506392c Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Thu, 29 Feb 2024 09:17:00 +0000 Subject: [PATCH] Fucking leap years2 --- on_this_day.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/on_this_day.py b/on_this_day.py index 27f4575..1cf94ab 100755 --- a/on_this_day.py +++ b/on_this_day.py @@ -27,15 +27,19 @@ while (year_counter >= year_joined ) : year_counter -= 1 # The end of today is the start of tomorrow # This means yesterday can take into account leap-years - today_end = datetime(year_counter, month_now, day_now, 00, 00) + timedelta(days=1) - yesterday_end = today_end - timedelta(days=1) - # Bitwise shift the integer representation and convert to milliseconds - max_id = ( int( today_end.timestamp() ) << 16 ) * 1000 - min_id = ( int( yesterday_end.timestamp() ) << 16 ) * 1000 - # Call the API - statuses = mastodon.account_statuses(id = my_id, max_id=max_id, min_id=min_id, limit="40", exclude_reblogs=True) - # Fetch further statuses if there are any - all_statuses = statuses #mastodon.fetch_remaining(statuses) - # Print the date and URl - for status in all_statuses : - print( str(status["created_at"])[:16] + " " + BeautifulSoup(status["content"], features="html.parser").get_text() + " - " + status["uri"] + "\n") + try: + today_end = datetime(year_counter, month_now, day_now, 00, 00) + timedelta(days=1) + yesterday_end = today_end - timedelta(days=1) + # Bitwise shift the integer representation and convert to milliseconds + max_id = ( int( today_end.timestamp() ) << 16 ) * 1000 + min_id = ( int( yesterday_end.timestamp() ) << 16 ) * 1000 + # Call the API + statuses = mastodon.account_statuses(id = my_id, max_id=max_id, min_id=min_id, limit="40", exclude_reblogs=True) + # Fetch further statuses if there are any + all_statuses = statuses #mastodon.fetch_remaining(statuses) + # Print the date and URl + for status in all_statuses : + print( str(status["created_at"])[:16] + " " + BeautifulSoup(status["content"], features="html.parser").get_text() + " - " + status["uri"] + "\n") + except: + print( str(year_counter) + " is not a leap year.") + \ No newline at end of file