Skip to content

Commit

Permalink
Timezone aware timestamps fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ichalkiad committed Jul 1, 2024
1 parent 12660ae commit b69e8a2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pymstdncollect/src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def execute_update_context_sql(dbconnection, table, headtoot, repliestoot, auth_
monthyear = pd.Timestamp(np.datetime64(parenttoot["created_at"])).tz_localize("CET").astimezone(pytz.utc)
except:
monthyear = pd.Timestamp(np.datetime64(parenttoot["created_at"])).tz_localize("Europe/Paris").astimezone(pytz.utc)
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')):
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d').tz_localize("Europe/Paris").astimezone(pytz.utc)):
# do not collect it, in_reply_to_id field of reply remains unchanged
continue
parentglobalID = parenttoot["globalID"]
Expand Down
4 changes: 2 additions & 2 deletions pymstdncollect/src/toots.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def collect_user_postingactivity_apidirect(useracct, instance_name, savedir="/tm

print(monthyear)

if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')):
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')).tz_localize("Europe/Paris").astimezone(pytz.utc):
# do not collect it
continue
i["instance_name"] = tootinstance
Expand Down Expand Up @@ -499,7 +499,7 @@ def contains_kw(x): return x.lower() in toottext
monthyear = pd.Timestamp(np.datetime64(parenttoot["created_at"])).tz_localize("CET").astimezone(pytz.utc)
except:
monthyear = pd.Timestamp(np.datetime64(parenttoot["created_at"])).tz_localize("Europe/Paris").astimezone(pytz.utc)
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')):
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')).tz_localize("Europe/Paris").astimezone(pytz.utc):
# do not collect it
raise AttributeError
parenttoot["account"] = add_unique_account_id(parenttoot["account"], i["instance_name"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def collect_timeline_hashtag_apidirect(hashtag=None, url=None, local=False, remo
monthyear = pd.Timestamp(np.datetime64(idesc["created_at"])).tz_localize("CET").astimezone(pytz.utc)
except:
monthyear = pd.Timestamp(np.datetime64(idesc["created_at"])).tz_localize("Europe/Paris").astimezone(pytz.utc)
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')):
if monthyear < pd.Timestamp(cutoff_date).tz_localize("Europe/Paris").astimezone(pytz.utc) or monthyear > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')).tz_localize("Europe/Paris").astimezone(pytz.utc):
# do not collect it
continue

Expand Down
2 changes: 1 addition & 1 deletion pymstdncollect/user_scripts/weekly_postcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def weekly_users_postcollection(sourcedir, mindate, maxdate, dbconn=None, outdir
tootdate = pd.Timestamp(np.datetime64(usertoot["created_at"])).tz_localize("CET").astimezone(pytz.utc)
except:
tootdate = pd.Timestamp(np.datetime64(usertoot["created_at"])).tz_localize("Europe/Paris").astimezone(pytz.utc)
if tootdate < mindate or tootdate > maxdate or tootdate > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')):
if tootdate < mindate or tootdate > maxdate or tootdate > pd.Timestamp(datetime.today().strftime('%Y-%m-%d')).tz_localize("Europe/Paris").astimezone(pytz.utc):
continue
# get boosts for user statuses of current week
reblogs = get_boosts(usertoot, row["instance_name"], auth_dict=auth_dict)
Expand Down

0 comments on commit b69e8a2

Please sign in to comment.