Spaces:
Sleeping
Sleeping
File size: 610 Bytes
e8c2906 |
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
def data_to_text(data):
text = ""
for contents in data.values():
for thread in contents["contents"]:
text += thread["title"] + " " + thread["self_text"] + " "
for comment in thread["comments"]:
text += comment["text"] + " "
return text
def json_to_text(json_file):
with open(json_file, "r") as f:
data = json.load(f)
text = ""
for thread in data:
text += thread["title"] + " " + thread["selftext"] + " "
for comment in thread["comments"]:
text += comment["body"] + " "
return text
|