WordCloud4Reddit / utils.py
sbgonenc96's picture
init commit
e8c2906 verified
raw
history blame contribute delete
610 Bytes
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