Skip to content

Commit 25ed9e4

Browse files
committed
address peer review
1 parent 4a94fb4 commit 25ed9e4

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

process.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import pathlib
3-
from datetime import datetime, timedelta
3+
from datetime import datetime, timezone
44
import os
55
import requests
66

@@ -82,21 +82,11 @@
8282
article['states'] = states
8383
article['agencies'] = [agency['name'] for agency in article['agencies']]
8484

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')
9889
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
10090

10191
if date_key not in articles_by_date:
10292
date_articles = []

0 commit comments

Comments
 (0)