enwiki_to_arwiki_categories / fix langlinks.py
Ibrahemqasim's picture
Create fix langlinks.py
8dc5272 verified
raw
history blame
1.58 kB
import re
import tqdm
import json
import requests
from huggingface_hub import login
from huggingface_hub import upload_file
# تسجيل الدخول إلى Hugging Face (استبدل "YOUR_ACCESS_TOKEN" بالتوكن الخاص بك)
login("YOUR_ACCESS_TOKEN")
# تحميل الملف JSON من الرابط مباشرة
json_url = "https://huggingface.co/Ibrahemqasim/enwiki_to_arwiki_categories/resolve/main/langlinks.json"
response = requests.get(json_url)
data = response.json()
# تحويل القاموس إلى قائمة من القواميس [{ "en": "value", "ar": "value" }, ...]
data_list = []
for key, value in tqdm.tqdm(data.items()):
# "Category:1. FC Köln non-playing staff"
# remove " from start and end
# ---
if key.startswith('"') and key.endswith('"'):
key = key[1:-1]
# ----
# remove (:") from start and remove (",) from end
# :"cc",
if value.startswith(':"') and value.endswith('",'):
value = value[2:-2]
# ----
data_list.append({"en": key, "ar": value})
# حفظ القاموس المصحح في ملف JSON
with open("langlinks_fixed.json", "w", encoding="utf-8") as f:
json.dump(data_list, f, ensure_ascii=False, indent=4)
upload_file(
path_or_fileobj="langlinks_fixed.json", # اسم الملف الذي تم حفظه
path_in_repo="langlinks_fixed.json", # المسار داخل المستودع
repo_id="Ibrahemqasim/enwiki_to_arwiki_categories", # معرف المستودع
# repo_type="dataset", # نوع المستودع (نستخدم dataset للملفات)
)