-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathundoc_chars_auto.py
More file actions
134 lines (100 loc) · 4.57 KB
/
undoc_chars_auto.py
File metadata and controls
134 lines (100 loc) · 4.57 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import tkinter as tk
from tkinter import filedialog
import json
import csv
import os
import requests
# Change this if you don't want it
AUTO_DOWNLOAD = True
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:
print("\n--------------------\nUndocumented Characters:")
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:
raise FileNotFoundError("No files selected.")
# Run auto download here
if AUTO_DOWNLOAD:
csv_filenames = download_files()
if not csv_filenames:
raise ValueError("No CSV files were downloaded")
for file_path in file_paths:
_, ext = os.path.splitext(file_path)
if ext.lower() == '.json':
json_filename = file_path
elif ext.lower() == '.csv' and not AUTO_DOWNLOAD:
csv_filenames.append(file_path)
else:
print(f"Ignoring 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 download_files():
# Change filename parameter if you want to save them as something else
csv_filenames = []
files_to_download = [
{
"url": "https://docs.google.com/spreadsheets/d/1PRtlXvjbHs4ulct6gSbYc6VYrQegU7HZ5SdhThkHuoY/export?format=csv&gid=1586918317",
"filename": "Unicode Characters Auto.csv"
},
{
"url": "https://docs.google.com/spreadsheets/d/1PRtlXvjbHs4ulct6gSbYc6VYrQegU7HZ5SdhThkHuoY/export?format=csv&gid=2129412547",
"filename": "Hangul Auto.csv"
},
{
"url": "https://docs.google.com/spreadsheets/d/1PRtlXvjbHs4ulct6gSbYc6VYrQegU7HZ5SdhThkHuoY/export?format=csv&gid=1446897313",
"filename": "CJK Unified Ideographs Auto.csv"
}
]
for file_info in files_to_download:
response = requests.get(file_info["url"])
filename = file_info["filename"]
with open(filename, "wb") as file:
file.write(response.content)
print(f"File downloaded and saved as {file_info['filename']}")
csv_filenames.append(filename)
return csv_filenames
def main():
json_filename, csv_filenames = find_files()
filedata = FileData(json_filename, csv_filenames)
if __name__ == '__main__':
main()