Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jan 2, 2025
1 parent d0cf246 commit ef59457
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/cron_market_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,30 @@ def convert_timestamps(data_list):

for item in data_list:
try:
# First, handle the microseconds by splitting on '.'
# Get the timestamp and split on '.'
timestamp = item['timestamp']
base_time = timestamp.split('.')[0]

# If there are microseconds, add them back in the correct format
# Handle microseconds if present
if '.' in timestamp:
microseconds = timestamp.split('.')[1].replace('Z', '')
# Pad with zeros if needed
microseconds = microseconds.ljust(6, '0')
microseconds = microseconds.ljust(6, '0') # Pad with zeros if needed
base_time = f"{base_time}.{microseconds}"

# Replace 'Z' with '+00:00' for UTC
# Replace 'Z' with '+00:00' (for UTC)
base_time = base_time.replace('Z', '+00:00')

# Parse the timestamp
dt = datetime.fromisoformat(base_time)

# Convert to New York timezone
# Ensure the datetime is timezone-aware (assumed to be UTC initially)
if dt.tzinfo is None:
dt = pytz.utc.localize(dt)

# Convert the time to New York timezone (automatically handles DST)
ny_time = dt.astimezone(ny_tz)

# Format the timestamp
# Optionally, format to include date and time
item['timestamp'] = ny_time.strftime('%Y-%m-%d %H:%M:%S')

except ValueError as e:
Expand Down Expand Up @@ -340,8 +343,8 @@ def main():
data = {'sectorData': sector_data, 'topSectorTickers': top_sector_tickers, 'marketTide': market_tide}
if len(data) > 0:
save_json(data)




if __name__ == '__main__':
main()

0 comments on commit ef59457

Please sign in to comment.