├── .gitignore ├── README.md ├── main.py └── usage.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSON to HTML and EXCEL 2 | 3 | Simple python 3 script to convert Discord json chats to html or xls for easier reading. 4 | 5 | For an explanation on how to find Discord app chats in Windows see here: 6 | 7 | https://abrignoni.blogspot.com/2018/03/finding-discord-app-chats-in-windows.html 8 | 9 | Required modules: 10 | 11 | `` pip install json2html `` 12 | 13 | `` pip install pandas `` 14 | 15 | `` pip install xlsxwriter `` 16 | 17 | `` pip install xlwt `` 18 | 19 | **Usage:** 20 | 21 | 1. Run the main.py script 22 | 2. Write the path to the directory that contains the Discord chat json files. 23 | 3. Select conversion format. Select #1 for html or #2 for xls. 24 | 4. Converted files will be located in a new folder within the Discord chat json files directory. 25 | 26 | ![alt text](usage.jpg "Usage example") 27 | 28 | **Note** 29 | All json files have to be in the selected directory. Script will not due a recursive search. 30 | 31 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import sys, os, json 2 | import pandas as pd 3 | from json2html import * 4 | 5 | loop = 1 6 | count = 0 7 | checkerrors = 0 8 | 9 | print("Convert JSON Discord chats to HTML or XLS") 10 | print() 11 | print("https://abrignoni.blogspot.com") 12 | print("Twitter: @AlexisBrignoni") 13 | print() 14 | 15 | while loop == 1: 16 | print ("Write path to files: ") 17 | path2input = input() 18 | if os.path.exists(path2input): 19 | #print ("Directory exists -> "+path2input) 20 | loop = 2 21 | else: 22 | print ("Directory does not exist.") 23 | 24 | while loop == 2: 25 | print() 26 | print ("Select conversion format:") 27 | print ("1: HTML") 28 | print ("2: XLS") 29 | selected = input() 30 | if (selected == "1"): 31 | loop = 3 32 | print() 33 | print ("HTML selected") 34 | print() 35 | 36 | elif (selected == "2"): 37 | print() 38 | print ("XLS selected") 39 | print() 40 | loop = 3 41 | else: 42 | print ("Invalid selection.") 43 | 44 | 45 | if (selected == "2"): 46 | # open folder to write to 47 | os.makedirs(path2input + "/" + "converted-XLS" + "/") 48 | #open folder to read from 49 | for filename in os.listdir(path2input): 50 | count = count+1 51 | if os.path.isdir(path2input + "/" + filename): 52 | count=count-1 #make sure a directory check does not count as a processed file. 53 | else: 54 | try: 55 | file = open(path2input + "/" + filename, 'r') 56 | input = file.read() 57 | file.close() 58 | data = pd.read_json(input) 59 | data.to_excel(path2input + "/" + "converted-XLS" + "/" + filename +'.xls', index=False) 60 | except: 61 | checkerrors = 1; 62 | print("Unable to convert: "+ path2input + '/' + filename) 63 | errors = open(path2input + "/converted-XLS/error.txt", 'a') 64 | errors.write("Unable to convert: "+ path2input + '/' + filename + '\n') 65 | errors.close() 66 | pass 67 | 68 | if (selected == "1"): 69 | os.makedirs(path2input + "/" + "converted-HTML" + "/") 70 | for filename in os.listdir(path2input): 71 | count = count+1 72 | if os.path.isdir(path2input + "/" + filename): 73 | count=count-1 74 | else: 75 | try: 76 | file = open(path2input + "/" + filename, 'r', encoding="utf-8") 77 | input = file.read() 78 | file.close() 79 | 80 | afuera = json2html.convert(json = input, clubbing = False) 81 | 82 | file = open(path2input + "/" + "converted-HTML" + "/" + filename +'.html', 'w', encoding="utf-8") 83 | file.write(afuera) 84 | file.close() 85 | except: 86 | print(f'The {filename} file is not a valid json object') 87 | count=count-1 88 | 89 | print() 90 | print("Files processed: "+ str(count)) 91 | print() 92 | 93 | if (checkerrors == 1): 94 | print("See error log: "+ path2input + "/" + "converted-XLS" + "/errors.txt" + ". Process as HTML to view contents of these files." ) 95 | 96 | 97 | if (selected == "2"): 98 | print() 99 | print("Converted files located at: " + path2input + "/" + "converted-HTML" + "/") 100 | print() 101 | print("Script will now close.") 102 | os.system('pause') 103 | 104 | if (selected == "1"): 105 | print() 106 | print("Converted files located at: " + path2input + "/" + "converted-XLS" + "/") 107 | print() 108 | print("Script will now close.") 109 | os.system('pause') 110 | -------------------------------------------------------------------------------- /usage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abrignoni/JSON-to-HTML-and-XLS/cd9b80db2c8e3de7c2feda11b356aef8d65df29c/usage.jpg --------------------------------------------------------------------------------