-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcrawler_utils.py
More file actions
24 lines (19 loc) · 815 Bytes
/
crawler_utils.py
File metadata and controls
24 lines (19 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import json
import os.path
def comments_to_json(comments):
result = []
for comment in comments:
result.append({"score": comment.score,
"url": comment.permalink,
"body": comment.body,
"id": comment.id,
"replies": comments_to_json(comment.replies)})
return result
def save_submission(submission, storage_dir):
with open(os.path.join(storage_dir, submission.id), "w") as f:
f.write(json.dumps({"url": submission.permalink,
"text": submission.selftext,
"title": submission.title,
"score": submission.score,
"comments": comments_to_json(submission.comments)}))
f.close()