Skip to content

Commit b37fb42

Browse files
committed
Change: add date to instagram title
1 parent e1ce90b commit b37fb42

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

comiccrawler/mods/instagram.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
import json
7+
from datetime import datetime
78
from html import unescape
89
from urllib.parse import urlparse
910

@@ -57,6 +58,10 @@ def get_episodes_from_data(data):
5758
if timeline["page_info"]["has_next_page"]:
5859
end_cursor = timeline["page_info"]["end_cursor"]
5960
return reversed(eps), end_cursor
61+
62+
def ts_to_date(ts):
63+
dt = datetime.fromtimestamp(ts)
64+
return dt.strftime("%y-%m-%d")
6065

6166
def get_episodes(html, url):
6267
if match := re.match(r"https://www\.instagram\.com/([^/]+)/", url):
@@ -71,8 +76,12 @@ def get_episodes(html, url):
7176
body = json.loads(html)
7277
result = []
7378
for item in body["items"]:
79+
try:
80+
ts = item["taken_at"]
81+
except KeyError:
82+
ts = item["caption"]["created_at"]
7483
result.append(Episode(
75-
str(item["code"]),
84+
f"{ts_to_date(ts)} {item['code']}",
7685
f"https://www.instagram.com/p/{item['code']}/"
7786
))
7887

0 commit comments

Comments
 (0)