Files

70 lines
1.4 KiB
Python

#class used for creating json files for output to user
from createOutput import outputPrep
"""
json template:
post #
|- link
|
|- "metadata"
| |- user
| |- date
| |- edit date
|
|- "content"
| |- raw html
| |- raw text
| |- formated text with media/stuff
| |- attachments
|
|- "ratings"
| |- "specific"
| | |- Like
| | |- Dislike
| | |- Agree
| | |- Disagree
| | |- Winner
| | |- Informative
| | |- Thunk-Provoking
| | |- Feels
| | |- Islamic Content
| | |- Lunacy
| | |- Autistic
| | |- Horrifying
| | |- Optimistic
| | |- TMI
| | |- Late
| | |- Dumb
| | |- Mad at the Internet
| | |- Semper Fidelis
| | |- Devient
| | |- Achievement
| | |- DRINK!
| |- positive
| |- neutral
| |- negative
| |- weighted score
| |- total ratings
"""
from postData import PostData
import json
class JsonConvert(outputPrep.outputPrep):
def exportJson(self, path, fileName):
#creates json file using postData dictionary and saves it at path
#returns true if success, false otherwise
#
#path = file location to save json to
#filename = name of json file
try:
with open(path + "\\" + fileName + ".json", "w") as export:
json.dump(self.postData, export)
return True #no errors
except:
print(self.postData)
return False #unable to write to/create file