|
1 | 1 | import json |
2 | 2 | import pathlib |
3 | | -from datetime import datetime, timedelta |
| 3 | +from datetime import datetime, timezone |
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 | | - # 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) |
90 | | - |
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 |
| 85 | + # adjust timezone info into UTC time |
| 86 | + article['created_at'] = article['created_at'][:-3] + "00" # %z only accepts `-0400` instead of `-04:00` in Python3.6 |
| 87 | + created_at = datetime.strptime(article['created_at'], '%Y-%m-%dT%H:%M:%S.%f%z').astimezone(timezone.utc) |
| 88 | + article['created_at'] = created_at.strftime('%Y-%m-%dT%H:%M:%S.%f') |
98 | 89 | 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 |
100 | 90 |
|
101 | 91 | if date_key not in articles_by_date: |
102 | 92 | date_articles = [] |
|
0 commit comments