Update app.py
Browse files
app.py
CHANGED
|
@@ -36,6 +36,14 @@ def blob_to_base64_html(blob_data):
|
|
| 36 |
except Exception as e:
|
| 37 |
return str(blob_data)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def natural_sort_key(s):
|
| 40 |
if s is None:
|
| 41 |
return []
|
|
@@ -82,6 +90,9 @@ def update_category_dd(standard, version):
|
|
| 82 |
try:
|
| 83 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 84 |
conn = sqlite3.connect(target["path"])
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
|
| 87 |
main_t = f"{standard}_{version}"
|
|
@@ -101,7 +112,7 @@ def update_category_dd(standard, version):
|
|
| 101 |
for _, r in df.iterrows():
|
| 102 |
choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
|
| 103 |
|
| 104 |
-
# 2.
|
| 105 |
pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
|
| 106 |
|
| 107 |
for t in tables:
|
|
@@ -141,7 +152,7 @@ def highlight_diff(base, comp):
|
|
| 141 |
|
| 142 |
d = list(difflib.ndiff(b_words, c_words))
|
| 143 |
|
| 144 |
-
b_res, c_res = []
|
| 145 |
i = 0
|
| 146 |
|
| 147 |
while i < len(d):
|
|
@@ -178,6 +189,9 @@ def display_data(standard, version, selection):
|
|
| 178 |
try:
|
| 179 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 180 |
conn = sqlite3.connect(target["path"])
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
tables = pd.read_sql(
|
| 183 |
"SELECT name FROM sqlite_master WHERE type='table';",
|
|
@@ -245,14 +259,8 @@ def display_data(standard, version, selection):
|
|
| 245 |
# ๐น ALL ์ ํ
|
| 246 |
# --------------------------
|
| 247 |
if selection == "ALL":
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
if real_cat:
|
| 251 |
-
query += f"""
|
| 252 |
-
WHERE IFNULL(UPPER(TRIM(CAST([{real_cat}] AS TEXT))), '') != 'TABLE'
|
| 253 |
-
"""
|
| 254 |
-
|
| 255 |
-
cursor.execute(query)
|
| 256 |
|
| 257 |
# --------------------------
|
| 258 |
# ๐น chapter.category
|
|
@@ -309,7 +317,7 @@ def apply_diff_row(row, base_col, comp_col):
|
|
| 309 |
if "<img" in base_val or "<img" in comp_val:
|
| 310 |
return pd.Series([base_val, comp_val])
|
| 311 |
|
| 312 |
-
#
|
| 313 |
if base_val == comp_val:
|
| 314 |
return pd.Series([base_val, comp_val])
|
| 315 |
|
|
@@ -359,7 +367,7 @@ def unified_search(bs, bv, bc, cs, cv, cc):
|
|
| 359 |
# NaN ๊ฐ์ ๋น ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ
|
| 360 |
merged = merged.fillna("")
|
| 361 |
|
| 362 |
-
#
|
| 363 |
merged[[base_col, comp_col]] = merged.apply(
|
| 364 |
lambda row: apply_diff_row(row, base_col, comp_col),
|
| 365 |
axis=1
|
|
@@ -423,7 +431,7 @@ with gr.Blocks() as demo:
|
|
| 423 |
comp_reset_btn.click(reset_comp, None, [comp_standard, comp_version, comp_category])
|
| 424 |
|
| 425 |
# --------------------------
|
| 426 |
-
# CSS
|
| 427 |
# --------------------------
|
| 428 |
css = """
|
| 429 |
table {
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return str(blob_data)
|
| 38 |
|
| 39 |
+
# ๐ [ํต์ฌ ์ถ๊ฐ] ํ
์คํธ ๋์ฝ๋ฉ ์๋ฌ ๋ฐฉ์ง์ฉ ํฉํ ๋ฆฌ ํจ์
|
| 40 |
+
def safe_text_factory(x):
|
| 41 |
+
"""ํ
์คํธ ๋์ฝ๋ฉ์ ์๋ํ๊ณ , ์คํจํ๋ฉด(PNG ๋ฑ ์ด๋ฏธ์ง์ผ ๊ฒฝ์ฐ) ์๋ณธ ๋ฐ์ดํธ๋ฅผ ๊ทธ๋๋ก ๋ฐํ"""
|
| 42 |
+
try:
|
| 43 |
+
return x.decode('utf-8')
|
| 44 |
+
except UnicodeDecodeError:
|
| 45 |
+
return x
|
| 46 |
+
|
| 47 |
def natural_sort_key(s):
|
| 48 |
if s is None:
|
| 49 |
return []
|
|
|
|
| 90 |
try:
|
| 91 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 92 |
conn = sqlite3.connect(target["path"])
|
| 93 |
+
|
| 94 |
+
# ๐ [ํต์ฌ ์ถ๊ฐ] ์นดํ
๊ณ ๋ฆฌ ๋ถ๋ฌ์ฌ ๋๋ ์ด๋ฏธ์ง ์๋ฌ ์ฐจ๋จ
|
| 95 |
+
conn.text_factory = safe_text_factory
|
| 96 |
|
| 97 |
tables = pd.read_sql("SELECT name FROM sqlite_master WHERE type='table';", conn)['name'].tolist()
|
| 98 |
main_t = f"{standard}_{version}"
|
|
|
|
| 112 |
for _, r in df.iterrows():
|
| 113 |
choices.append(f"{str(r[ch]).strip()}.{str(r[ca]).strip()}")
|
| 114 |
|
| 115 |
+
# 2. ํ
์ด๋ธ ์ด๋ฆ ๊น๋ํ๊ฒ ์๋ฅด๊ธฐ (๊ฐ๋ ฅํ ์ ๊ท์ ์ ์ฉ)
|
| 116 |
pattern = re.compile(f"^{standard}[_\\s-]*{version}[_\\s-]*", re.IGNORECASE)
|
| 117 |
|
| 118 |
for t in tables:
|
|
|
|
| 152 |
|
| 153 |
d = list(difflib.ndiff(b_words, c_words))
|
| 154 |
|
| 155 |
+
b_res, c_res = []
|
| 156 |
i = 0
|
| 157 |
|
| 158 |
while i < len(d):
|
|
|
|
| 189 |
try:
|
| 190 |
target = next(d for d in db_registry if d["standard"] == standard and d["version"] == version)
|
| 191 |
conn = sqlite3.connect(target["path"])
|
| 192 |
+
|
| 193 |
+
# ๐ [ํต์ฌ ์ถ๊ฐ] ๋ฐ์ดํฐ ์กฐํ ์ ์ด๋ฏธ์ง ์๋ฌ ์๋ฒฝ ์ฐจ๋จ!
|
| 194 |
+
conn.text_factory = safe_text_factory
|
| 195 |
|
| 196 |
tables = pd.read_sql(
|
| 197 |
"SELECT name FROM sqlite_master WHERE type='table';",
|
|
|
|
| 259 |
# ๐น ALL ์ ํ
|
| 260 |
# --------------------------
|
| 261 |
if selection == "ALL":
|
| 262 |
+
# ๐ [์์ ] ํ
์คํธ ํฉํ ๋ฆฌ๋ก ์๋ฌ๋ฅผ ์ก์์ผ๋ฏ๋ก, ๋ถํ์ํ ํํฐ ์กฐ๊ฑด ์ญ์
|
| 263 |
+
cursor.execute(f"SELECT * FROM [{main_t}]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
# --------------------------
|
| 266 |
# ๐น chapter.category
|
|
|
|
| 317 |
if "<img" in base_val or "<img" in comp_val:
|
| 318 |
return pd.Series([base_val, comp_val])
|
| 319 |
|
| 320 |
+
# 2. [ํต์ฌ] ๋ ํ
์คํธ๊ฐ ์์ ํ ๋๊ฐ์ผ๋ฉด ๋ฌด๊ฑฐ์ด diff ์ฐ์ฐ ์๋ต (Fast-path)
|
| 321 |
if base_val == comp_val:
|
| 322 |
return pd.Series([base_val, comp_val])
|
| 323 |
|
|
|
|
| 367 |
# NaN ๊ฐ์ ๋น ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ
|
| 368 |
merged = merged.fillna("")
|
| 369 |
|
| 370 |
+
# ์ต์ ํ ํฌ์ธํธ: iterrows() ๋์ apply() ์ฌ์ฉ
|
| 371 |
merged[[base_col, comp_col]] = merged.apply(
|
| 372 |
lambda row: apply_diff_row(row, base_col, comp_col),
|
| 373 |
axis=1
|
|
|
|
| 431 |
comp_reset_btn.click(reset_comp, None, [comp_standard, comp_version, comp_category])
|
| 432 |
|
| 433 |
# --------------------------
|
| 434 |
+
# CSS
|
| 435 |
# --------------------------
|
| 436 |
css = """
|
| 437 |
table {
|