#class for creating text files for output to user """ text template: # [post number]: Link: [link] Metadata: User: [username] Date: [post date] Edit Date: [date of edit] Content: Raw HTML: [raw HTML code] Raw Text: [raw text from post] Formated Text: [formated text with media/stuff] Attatchments: [links to attatchments] Ratings: Specific: Like: [# recieved] Dislike: [# recieved] Agree: [# recieved] Disagree: [# recieved] Winner: [# recieved] Informative: [# recieved] Thunk-Provoking: [# recieved] Feels: [# recieved] Islamic Content: [# recieved] Lunacy: [# recieved] Autistic: [# recieved] Horrifying: [# recieved] Optimistic: [# recieved] TMI: [# recieved] Late: [# recieved] Dumb: [# recieved] Mad at the Internet: [# recieved] Semper Fidelis: [# recieved] Devient: [# recieved] Achievement: [# recieved] DRINK!: [# recieved] Positive: [# positive ratings] Negative: [# negative ratings] Neutral: [# neutral ratings] Weighted Score: [weighted score] Total Ratings: [# overall ratings] """ from createOutput import outputPrep from postData import PostData class TextConvert(outputPrep.outputPrep): def makeTextForOutput(self): #returns contents of postData dictionary in text form textContents = "" #text to be returned for postNum, postContents in self.postData.items(): textContents = f"""{textContents} {postNum}: Link: {postContents["link"]} Metadata: User: {postContents["metadata"]["user"]} Date: {postContents["metadata"]["date"]} Edit Date: {postContents["metadata"]["edit date"]} Content: Raw HTML: {postContents["content"]["raw html"]} Raw Text: {postContents["content"]["raw text"]} Formated Text: {postContents["content"]["formated text"]} Attatchments: {postContents["content"]["attachments"]} Ratings: Specific: Like: {postContents["ratings"]["specific ratings"]["Like"]} Dislike: {postContents["ratings"]["specific ratings"]["Dislike"]} Agree: {postContents["ratings"]["specific ratings"]["Agree"]} Disagree: {postContents["ratings"]["specific ratings"]["Disagree"]} Winner: {postContents["ratings"]["specific ratings"]["Winner"]} Informative: {postContents["ratings"]["specific ratings"]["Informative"]} Thunk-Provoking: {postContents["ratings"]["specific ratings"]["Thunk-Provoking"]} Feels: {postContents["ratings"]["specific ratings"]["Feels"]} Islamic Content: {postContents["ratings"]["specific ratings"]["Islamic Content"]} Lunacy: {postContents["ratings"]["specific ratings"]["Lunacy"]} Autistic: {postContents["ratings"]["specific ratings"]["Autistic"]} Horrifying: {postContents["ratings"]["specific ratings"]["Horrifying"]} Optimistic: {postContents["ratings"]["specific ratings"]["Optimistic"]} TMI: {postContents["ratings"]["specific ratings"]["TMI"]} Late: {postContents["ratings"]["specific ratings"]["Late"]} Dumb: {postContents["ratings"]["specific ratings"]["Dumb"]} Mad at the Internet: {postContents["ratings"]["specific ratings"]["Mad at the Internet"]} Semper Fidelis: {postContents["ratings"]["specific ratings"]["Semper Fidelis"]} Deviant: {postContents["ratings"]["specific ratings"]["Deviant"]} Achievement: {postContents["ratings"]["specific ratings"]["Achievement"]} DRINK!: {postContents["ratings"]["specific ratings"]["DRINK!"]} Positive: {postContents["ratings"]["positive ratings"]} Negative: {postContents["ratings"]["negative ratings"]} Neutral: {postContents["ratings"]["neutral ratings"]} Weighted Score: {postContents["ratings"]["weighted score"]} Total Ratings: {postContents["ratings"]["total ratings"]} """ return textContents def exportText(self, path, fileName): #creates text file using makeTextForOutput and saves it at path at fileName #returns true if success, false otherwise # #path = file locatino to save text file to #fileName = name of text file try: with open(path + "\\" + fileName + ".txt", "w") as export: export.write(self.makeTextForOutput()) return True #no errors except: return False #unable to write to/create file