Skip to content

Commit c824621

Browse files
committed
Treat Foursquare timestamps as UTC, closes #5
1 parent 5da1811 commit c824621

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

swarm_to_sqlite/cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
)
1414
@click.option("--token", envvar="FOURSQUARE_TOKEN", help="Foursquare OAuth token")
1515
@click.option(
16-
"--load",
17-
type=click.File(),
18-
help="Load checkins from this JSON file on disk",
16+
"--load", type=click.File(), help="Load checkins from this JSON file on disk"
1917
)
2018
@click.option(
21-
"--save",
22-
type=click.File("w"),
23-
help="Save checkins to this JSON file on disk",
19+
"--save", type=click.File("w"), help="Save checkins to this JSON file on disk"
2420
)
2521
@click.option("-s", "--silent", is_flag=True, help="Don't show progress bar")
2622
def cli(db_path, token, load, save, silent):

swarm_to_sqlite/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def save_checkin(checkin, db):
4343
else:
4444
checkin["sticker"] = None
4545

46-
checkin["created"] = datetime.datetime.fromtimestamp(
46+
checkin["created"] = datetime.datetime.utcfromtimestamp(
4747
checkin["createdAt"]
4848
).isoformat()
4949
checkin["source"] = db["sources"].lookup(checkin["source"])
@@ -77,7 +77,7 @@ def save_checkin(checkin, db):
7777
# Handle photos
7878
photos_table = db.table("photos", pk="id", foreign_keys=("user", "source"))
7979
for photo in photos:
80-
photo["created"] = datetime.datetime.fromtimestamp(
80+
photo["created"] = datetime.datetime.utcfromtimestamp(
8181
photo["createdAt"]
8282
).isoformat()
8383
photo["source"] = db["sources"].lookup(photo["source"])
@@ -89,7 +89,9 @@ def save_checkin(checkin, db):
8989
# Handle posts
9090
posts_table = db.table("posts", pk="id")
9191
for post in posts:
92-
post["created"] = datetime.datetime.fromtimestamp(post["createdAt"]).isoformat()
92+
post["created"] = datetime.datetime.utcfromtimestamp(
93+
post["createdAt"]
94+
).isoformat()
9395
post["post_source"] = (
9496
db["post_sources"].upsert(post.pop("source"), pk="id").last_pk
9597
)

tests/test_save_checkin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_photos(converted):
196196
"width": 1920,
197197
"height": 1440,
198198
"visibility": "public",
199-
"created": "2018-07-01T04:48:19",
199+
"created": "2018-07-01T02:48:19",
200200
"user": "15889193",
201201
},
202202
{
@@ -208,7 +208,7 @@ def test_photos(converted):
208208
"width": 1920,
209209
"height": 1440,
210210
"visibility": "public",
211-
"created": "2018-07-01T04:50:35",
211+
"created": "2018-07-01T02:50:35",
212212
"user": "15889193",
213213
},
214214
{
@@ -220,7 +220,7 @@ def test_photos(converted):
220220
"width": 1920,
221221
"height": 1440,
222222
"visibility": "public",
223-
"created": "2018-07-01T04:50:37",
223+
"created": "2018-07-01T02:50:37",
224224
"user": "15889193",
225225
},
226226
] == photos
@@ -246,7 +246,7 @@ def test_posts(converted):
246246
"text": "The samosa chaat appetizer (easily enough for two or even four people) was a revelation - I've never tasted anything quite like it before, absolutely delicious. Chicken tika masala was amazing too.",
247247
"url": "https://foursquare.com/item/58994045668af77dae50b376",
248248
"contentId": "58994045668af77dae50b376",
249-
"created": "2017-02-07T04:34:29",
249+
"created": "2017-02-07T03:34:29",
250250
"post_source": "UJXJTUHR42CKGO54KXQWGUZJL3OJKMKMVHGJ1SWIOC5TRKAC",
251251
"checkin": "592b2cfe09e28339ac543fde",
252252
}
@@ -269,7 +269,7 @@ def test_view(converted):
269269
assert [
270270
{
271271
"id": "592b2cfe09e28339ac543fde",
272-
"created": "2017-05-28T22:03:10",
272+
"created": "2017-05-28T20:03:10",
273273
"venue_id": "453774dcf964a520bd3b1fe3",
274274
"venue_name": "Restaurant Name",
275275
"latitude": 38.456,
@@ -282,8 +282,8 @@ def test_view(converted):
282282
] == list(converted["checkin_details"].rows)
283283
assert [
284284
{
285-
"first": "2017-05-28T22:03:10",
286-
"last": "2017-05-28T22:03:10",
285+
"first": "2017-05-28T20:03:10",
286+
"last": "2017-05-28T20:03:10",
287287
"count": 1,
288288
"venue_categories": "Category Name",
289289
"id": "453774dcf964a520bd3b1fe3",

0 commit comments

Comments
 (0)