hung9066 commited on
Commit
88b7a33
·
verified ·
1 Parent(s): 03a524e

Update Tu_Dong_Dien_Tu_21h.py (Localhost Only)

Browse files
Files changed (1) hide show
  1. Tu_Dong_Dien_Tu_21h.py +23 -19
Tu_Dong_Dien_Tu_21h.py CHANGED
@@ -1,12 +1,13 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
- Tu_Dong_Dien_Tu_21h.py - Tiến trình Tự Động Điền Từ & Cập Nhật Từ Điển Độc Lập
4
- Tự động:
5
  1. Đọc danh sách từ vựng tiếng Pháp (danh_sach_tu.txt) & tiếng Anh (danh_sach_tu_en.txt).
6
  2. Tự động sinh trọn bộ 29 trường chuẩn Note Type "(Anki) Template học từ vựng của Admin Phúc [2026]".
7
  3. Cập nhật vào Anki (qua AnkiConnect hoặc ghi trực tiếp SQLite).
8
- 4. Lưu ngược lại vào bộ từ điển ngoại tuyến (french_dictionary.db & english_dictionary.db).
9
- 5. Tự động đồng bộ lên Hugging Face Cloud (Web Mochi & Dataset).
 
10
  """
11
  import os
12
  import sys
@@ -20,7 +21,6 @@ import unicodedata
20
  import urllib.request
21
  import urllib.parse
22
  from pathlib import Path
23
- from concurrent.futures import ThreadPoolExecutor
24
 
25
  try:
26
  sys.stdout.reconfigure(encoding="utf-8")
@@ -250,30 +250,34 @@ def enrich_and_sync_deck(lang="fr"):
250
  print(f" [+] Đã hoàn tất chuẩn hóa {processed_count} từ mới vào Anki, file text và từ điển ngoại tuyến!")
251
 
252
 
253
- def sync_cloud():
 
254
  print("\n=======================================================")
255
- print(" [*] ĐỒNG BỘ 2 CHIỀU LÊN HUGGING FACE CLOUD")
256
  print("=======================================================")
257
- for script_name in ["Deploy_Va_Dong_Bo_Cloud.py", "Deploy_Va_Dong_Bo_English_Cloud.py"]:
258
- p = BASE_DIR / script_name
259
- if not p.exists():
260
- p = Path(r"C:\Users\ASUS\.gemini\antigravity\scratch\anki_web_server") / script_name
261
- if p.exists():
262
- try:
263
- os.system(f'python "{p}" --skip-media')
264
- except Exception as e:
265
- print(f" [!] Lỗi chạy {script_name}: {e}")
 
 
 
266
 
267
 
268
  def main():
269
  print("=======================================================")
270
- print(" 🚀 BẮT ĐẦU TIẾN TRÌNH TỰ ĐỘNG ĐIỀN TỪ & LƯU TỪ ĐIỂN 21H")
271
  print("=======================================================")
272
  enrich_and_sync_deck("fr")
273
  enrich_and_sync_deck("en")
274
- sync_cloud()
275
  print("\n=======================================================")
276
- print(" ✅ HOÀN THÀNH TOÀN BỘ TIẾN TRÌNH AUTOMATION!")
277
  print("=======================================================")
278
 
279
 
 
1
  # -*- coding: utf-8 -*-
2
  """
3
+ Tu_Dong_Dien_Tu_21h.py - Tiến trình Tự Động Điền Từ & Cập Nhật Từ Điển Độc Lập (CHỈ CHẠY LOCALHOST)
4
+ Hoàn toàn ngoại tuyến (Offline Localhost):
5
  1. Đọc danh sách từ vựng tiếng Pháp (danh_sach_tu.txt) & tiếng Anh (danh_sach_tu_en.txt).
6
  2. Tự động sinh trọn bộ 29 trường chuẩn Note Type "(Anki) Template học từ vựng của Admin Phúc [2026]".
7
  3. Cập nhật vào Anki (qua AnkiConnect hoặc ghi trực tiếp SQLite).
8
+ 4. Lưu ngược lại vào bộ từ điển ngoại tuyến máy tính (french_dictionary.db & english_dictionary.db).
9
+ 5. Tự động đồng bộ tiến độ vào cơ sở dữ liệu Localhost (web_progress.db).
10
+ KHÔNG ĐỒNG BỘ LÊN HUGGING FACE.
11
  """
12
  import os
13
  import sys
 
21
  import urllib.request
22
  import urllib.parse
23
  from pathlib import Path
 
24
 
25
  try:
26
  sys.stdout.reconfigure(encoding="utf-8")
 
250
  print(f" [+] Đã hoàn tất chuẩn hóa {processed_count} từ mới vào Anki, file text và từ điển ngoại tuyến!")
251
 
252
 
253
+ def sync_localhost_server():
254
+ """Tự động cập nhật cơ sở dữ liệu Localhost (server.py) để người dùng ôn tập được ngay"""
255
  print("\n=======================================================")
256
+ print(" [*] ĐỒNG BỘ DỮ LIỆU VÀO MÁY CHỦ WEB LOCALHOST (PORT 8686)")
257
  print("=======================================================")
258
+ server_dir = BASE_DIR
259
+ if not (server_dir / "server.py").exists():
260
+ server_dir = Path(r"C:\Users\ASUS\.gemini\antigravity\scratch\anki_web_server")
261
+ if (server_dir / "server.py").exists():
262
+ try:
263
+ sys.path.insert(0, str(server_dir))
264
+ import server
265
+ server.init_progress_db()
266
+ res = server.sync_from_anki_collection(force_overwrite_srs=False)
267
+ print(" [+] Kết quả đồng bộ Localhost:", res)
268
+ except Exception as e:
269
+ print(" [!] Lỗi đồng bộ vào server Localhost:", e)
270
 
271
 
272
  def main():
273
  print("=======================================================")
274
+ print(" 🚀 BẮT ĐẦU TIẾN TRÌNH TỰ ĐỘNG ĐIỀN TỪ & LƯU TỪ ĐIỂN (LOCAL ONLY)")
275
  print("=======================================================")
276
  enrich_and_sync_deck("fr")
277
  enrich_and_sync_deck("en")
278
+ sync_localhost_server()
279
  print("\n=======================================================")
280
+ print(" ✅ HOÀN THÀNH TOÀN BỘ TIẾN TRÌNH (CHỈ CHẠY MÁY CỤC BỘ / LOCALHOST)!")
281
  print("=======================================================")
282
 
283