|
1 | 1 | import json |
2 | 2 | import pathlib |
3 | | -from datetime import datetime |
| 3 | +from datetime import datetime, timedelta |
4 | 4 | import os |
5 | 5 | import requests |
6 | 6 |
|
|
82 | 82 | article['states'] = states |
83 | 83 | article['agencies'] = [agency['name'] for agency in article['agencies']] |
84 | 84 |
|
85 | | - # remove timezone info (-04:00) [NewYork] |
86 | | - article['created_at'] = article['created_at'][:-6] |
| 85 | + # adjust timezone info (e.g. -04:00) into UTC time |
| 86 | + timezone_adjust = article['created_at'][-5:] |
| 87 | + plus_or_minus = article['created_at'][-6] |
| 88 | + timezone_adjust = datetime.strptime(timezone_adjust, "%H:%M") |
| 89 | + timedelta_adjust = timedelta(hours=timezone_adjust.hour, minutes=timezone_adjust.minute) |
87 | 90 |
|
88 | | - # all data received during day T would confer into day T+1 00:00 |
89 | | - date = datetime.strptime(article['created_at'], '%Y-%m-%dT%H:%M:%S.%f').date() |
90 | | - date_key = date.strftime('%Y%m%d') |
| 91 | + created_at = datetime.strptime(article['created_at'][:-6], '%Y-%m-%dT%H:%M:%S.%f') |
| 92 | + if plus_or_minus == "+": |
| 93 | + created_at -= timedelta_adjust |
| 94 | + elif plus_or_minus == "-": |
| 95 | + created_at += timedelta_adjust |
| 96 | + |
| 97 | + # all data received during day T would confer into bar of Time = Day T 00:00; EndTime = Day T+1 00:00 at UTC time |
| 98 | + date_key = created_at.date().strftime('%Y%m%d') |
| 99 | + article['created_at'] = created_at.strftime('%Y-%m-%dT%H:%M:%S.%f') # UTC Time |
91 | 100 |
|
92 | 101 | if date_key not in articles_by_date: |
93 | 102 | date_articles = [] |
|
0 commit comments