GuglielmoTor commited on
Commit
f46bbe2
·
verified ·
1 Parent(s): 45a6b5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -225,6 +225,22 @@ def process_and_store_bubble_token(url_user_token, org_urn, token_state):
225
  follower_stats_need_sync = True
226
  logging.info("Follower stats need sync: No valid dates in monthly gains after conversion.")
227
  else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  # Sync if the last recorded gain is for a month *before* the start of the current month.
229
  # This ensures we attempt to fetch the previous month's data if it's not there.
230
  start_of_current_month = pd.Timestamp('now', tz='UTC').normalize().replace(day=1)
 
225
  follower_stats_need_sync = True
226
  logging.info("Follower stats need sync: No valid dates in monthly gains after conversion.")
227
  else:
228
+
229
+ # CRITICAL FIX: Ensure last_gain_date is timezone-aware (UTC) before comparison.
230
+ # pd.Timestamp.tzinfo is None checks if it's naive.
231
+ # pd.Timestamp.tzinfo.utcoffset(pd.Timestamp) is None is a more robust check for naivety.
232
+ if last_gain_date.tzinfo is None or last_gain_date.tzinfo.utcoffset(last_gain_date) is None:
233
+ # If last_gain_date is naive, localize it to UTC.
234
+ # This assumes naive dates should be interpreted as UTC.
235
+ last_gain_date = last_gain_date.tz_localize('UTC')
236
+ logging.info(f"Localized naive last_gain_date to UTC: {last_gain_date}")
237
+ else:
238
+ # If last_gain_date is already timezone-aware, convert it to UTC.
239
+ # This handles cases where it might be aware but in a different timezone.
240
+ # If it's already UTC, tz_convert('UTC') is a no-op.
241
+ last_gain_date = last_gain_date.tz_convert('UTC')
242
+ logging.info(f"Converted aware last_gain_date to UTC: {last_gain_date}")
243
+
244
  # Sync if the last recorded gain is for a month *before* the start of the current month.
245
  # This ensures we attempt to fetch the previous month's data if it's not there.
246
  start_of_current_month = pd.Timestamp('now', tz='UTC').normalize().replace(day=1)