-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndoc_chars.py
More file actions
86 lines (68 loc) · 3.06 KB
/
Undoc_chars.py
File metadata and controls
86 lines (68 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import tkinter as tk
from tkinter import filedialog
import json
import csv
import os
class FileData():
def __init__(self, json_file, csv_files):
self.json_file = json_file
self.csv_files = csv_files
self.character_statuses = {}
self.undocumented_characters = []
with open(self.json_file, 'r', encoding='utf-8') as f:
self.raw_data = json.load(f)
self.check_characters()
def check_characters(self):
json_uni_chars = {i for i in self.raw_data['recipes']} | {i['text'] for i in self.raw_data['elements']}
for csv_file in self.csv_files:
with open(csv_file, 'r', encoding='utf-8') as f:
csv_data = list(csv.reader(f))
for row in csv_data[1:]: # Skip the header row
name, unicode_hex, _, char, obtained = row[:5]
status = self.character_statuses.get(char, 0)
# If not yet added to statuses, add it
if not status:
self.character_statuses[char] = {'name': name, 'hex': unicode_hex, 'obtained': obtained.upper()}
# Override FALSE if its been found in a later version
elif status['obtained'] == 'FALSE' and obtained.upper() == 'TRUE':
self.character_statuses[char]['obtained'] = 'TRUE'
for char, status in self.character_statuses.items():
if status['obtained'] == 'FALSE' and char in json_uni_chars:
self.undocumented_characters.append((status['name'], status['hex'], char))
with open('undocumented_characters.txt', 'w', encoding='utf-8') as f:
for name, unicode_hex, char in self.undocumented_characters:
s = f'{name}\t{unicode_hex}\t{char}\n'
f.write(s)
print(end=s)
def select_files(filetypes):
"""Open a file dialog to select multiple files and return a list of file paths."""
root = tk.Tk()
root.withdraw() # Hide the root window
file_paths = filedialog.askopenfilenames(filetypes=filetypes)
return file_paths
def find_files():
file_paths = select_files([("All files", "*.*")])
json_filename = ''
csv_filenames = []
if not file_paths:
print("No files selected.")
return
# Process each selected file
for file_path in file_paths:
_, ext = os.path.splitext(file_path)
if ext.lower() == '.json':
json_filename = file_path
elif ext.lower() == '.csv':
csv_filenames.append(file_path)
else:
print(f"Ignoring non-JSON and non-CSV file: {file_path}")
if not json_filename:
raise FileNotFoundError("No JSON selected.")
if not csv_filenames:
raise FileNotFoundError("No CSV selected.")
return json_filename, csv_filenames
def main():
json_filename, csv_filenames = find_files()
filedata = FileData(json_filename, csv_filenames)
if __name__ == '__main__':
main()