-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabInspector.py
More file actions
39 lines (33 loc) · 1.11 KB
/
labInspector.py
File metadata and controls
39 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: UTF-8 -*-
import json
import requests
# writerNames = ["kmatthews25", ...]
r = requests.get("https://medium.com/code17?format=json")
data = json.loads(r.text.encode("utf-8")[16:])
users = data["payload"]["references"]["User"]
posts = data["payload"]["references"]["Post"]
usernames = {}
for k in list(users.keys()):
us = users[k]
usernames[us["userId"]] = {
"username": us["username"].encode("utf8"),
"name": us["name"].encode("utf8"),
}
template = "{username}, {name}, {userId}"
print(template.format(**us).encode("utf8"))
for k in list(posts.keys()):
p = posts[k]
tidyD = {}
tidyD["title"] = p["title"].strip()
tidyD["username"] = usernames[p["creatorId"]]["username"]
tidyD["name"] = usernames[p["creatorId"]]["name"].decode("utf-8")
tidyD["creatorId"] = p["creatorId"]
tidyD["firstPublishedAt"] = p["firstPublishedAt"]
# print tidyD
template = (
"{title}, "
"author: {username} - {name} ({creatorId}), "
"pub Date {firstPublishedAt}"
)
details = template.format(**tidyD)
print(details.encode("utf-8"))