From ee5decd6a8e9826a4ec013d83da32d931b0b5f85 Mon Sep 17 00:00:00 2001 From: Ibrahem Date: Wed, 8 Jul 2026 04:13:16 +0300 Subject: [PATCH] Refactor: Standardize naming conventions and reorganize imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comprehensive code cleanup across the codebase: - Standardized variable naming to follow PEP 8: `Qid` → `qid_str`, `NewDesc` → `new_desc_data`, `WD_API_Bot` → `WdApiBot`, constants to UPPERCASE - Reorganized imports with consistent blank line spacing between standard library, third-party, and local imports - Simplified import paths where applicable - Cleaned up verbose docstrings containing execution examples, replacing with minimal docstrings - Fixed string quote consistency and minor formatting issues - Function parameter names updated for consistency: `P` → `pid`, `Add` → `add_it`, `Tabs` → `tabs` - Removed commented-out CLI usage examples and outdated docstring content --- src/WDYe/common.py | 1 + src/WDYe/disam2.py | 1 + src/WDYe/med.py | 4 +- src/cy/cy_bot/cy_regs.py | 8 +-- src/cy/cy_bot/do_text.py | 26 ++++----- src/cy/jsub.py | 21 +------ src/cy/mv.py | 4 +- src/des/book.py | 70 ++++++++++++------------ src/des/desc.py | 46 +++++----------- src/des/fam.py | 49 ++++++++--------- src/des/film.py | 44 +++++++-------- src/des/galaxy.py | 4 +- src/des/na.py | 21 ++++--- src/des/numb.py | 20 +++---- src/des/places.py | 52 +++++++++--------- src/des/railway.py | 19 +++---- src/des/ru_st_2_latin.py | 11 ++-- src/desc_dicts/descraptions.py | 2 +- src/desc_dicts/descraptions_dict_new.py | 3 +- src/desc_dicts/taxones.py | 9 ++- src/desc_dicts/tiny_wrwr.py | 1 + src/nep/bots/helps.py | 15 ++--- src/nep/bots/its.py | 7 +-- src/nep/bots/scientific_article.py | 20 ++++--- src/nep/bots/tax_desc.py | 32 +++++------ src/nep/new_way.py | 9 +-- src/nep/nldesc.py | 9 +-- src/nep/others/read_json.py | 1 - src/nep/si3.py | 73 ++++++++++++------------- src/nep/si3g.py | 67 +---------------------- src/nep/si3g_qua.py | 14 +---- src/nep/space_others.py | 10 ++-- src/nep/tables/lists.py | 12 ++-- src/nep/tables/nats.py | 4 +- src/nep/tables/si_tables.py | 8 +-- src/nep/tables/str_descs.py | 7 +-- src/nep/wr_people.py | 13 +++-- src/neq/nldes3.py | 15 +---- src/neq/quarries.py | 12 ++-- src/people/Nationalities.py | 16 ++---- src/people/new3.py | 56 ++++++++----------- src/people/occupationsall.py | 20 +++---- src/people/people_get_topic.py | 2 +- src/prop_labs/fill_ar_props.py | 3 +- src/prop_labs/wd_Session.py | 1 + src/wd_gent.py | 3 +- 46 files changed, 340 insertions(+), 505 deletions(-) diff --git a/src/WDYe/common.py b/src/WDYe/common.py index 413bf46..6396a09 100644 --- a/src/WDYe/common.py +++ b/src/WDYe/common.py @@ -12,6 +12,7 @@ import logging import pywikibot + from bots_subs.wd_api import newdesc from desc_dicts.descraptions import DescraptionsTable diff --git a/src/WDYe/disam2.py b/src/WDYe/disam2.py index a41b47d..209e20c 100644 --- a/src/WDYe/disam2.py +++ b/src/WDYe/disam2.py @@ -11,6 +11,7 @@ import logging import pywikibot + from bots_subs import open_url from bots_subs.wd_api import wd_bot, wd_sparql_bot from bots_subs.wd_api.wd_desc import work_api_desc diff --git a/src/WDYe/med.py b/src/WDYe/med.py index a136a9c..beba178 100644 --- a/src/WDYe/med.py +++ b/src/WDYe/med.py @@ -13,12 +13,12 @@ import urllib import urllib.parse +from shared.api_page import load_main_api + from bots_subs import open_url from bots_subs.hi_api import HimoAPIBot from bots_subs.wd_api import wd_sparql_bot -from shared.api_page import load_main_api - WD_API_Bot = HimoAPIBot(mr_or_bot="mr", www="www") logger = logging.getLogger(__name__) diff --git a/src/cy/cy_bot/cy_regs.py b/src/cy/cy_bot/cy_regs.py index 3167240..a3deba9 100644 --- a/src/cy/cy_bot/cy_regs.py +++ b/src/cy/cy_bot/cy_regs.py @@ -1,10 +1,4 @@ -""" - -from .cy_regs import make_data_new - -python3 I:/core/bots/wd_core/cy/cy_bot/cy_regs.py - -""" +""" """ import wikitextparser as wtp diff --git a/src/cy/cy_bot/do_text.py b/src/cy/cy_bot/do_text.py index 60a264a..647c139 100644 --- a/src/cy/cy_bot/do_text.py +++ b/src/cy/cy_bot/do_text.py @@ -53,7 +53,7 @@ def template_params(text: str, title): # --- parser = wtp.parse(text) # --- - Qid = "" + qid_str = "" results = False # --- for template in parser.templates: @@ -80,13 +80,13 @@ def template_params(text: str, title): t_id = get_temp_arg(template, "id") if t_id: printt("** found currect line") - Qid = t_id - printt(f"id: {Qid}") + qid_str = t_id + printt(f"id: {qid_str}") results = True # --- break # --- - return Qid, results + return qid_str, results def findflag(race, flag): @@ -647,15 +647,15 @@ def make_new_text(item, title, text: str): Newsect = Frist + "\n" + Newsect + "{{نتيجة سباق الدراجات/نهاية}}" Newsect = re.sub(r"\n\n{{نتيجة سباق الدراجات/نهاية}}", "\n{{نتيجة سباق الدراجات/نهاية}}", Newsect) # --- - NewText = text.replace(old_sect, Newsect) + new_text = text.replace(old_sect, Newsect) # --- printt(f"showDiff of page: {title}
") # --- if title not in states: return text # --- - if states[title]["new_line"] != 0 or states[title]["removed_line"] != 0 and text != NewText: - return NewText + if states[title]["new_line"] != 0 or states[title]["removed_line"] != 0 and text != new_text: + return new_text else: printo("nodiff") # --- @@ -672,10 +672,10 @@ def do_One_Page(title, text: str, item: str = ""): # --- printt("**Isre: ") # --- - Qid, QidinTemplate = template_params(text, title) + qid_str, QidinTemplate = template_params(text, title) # --- if QidinTemplate: - item = Qid + item = qid_str # --- if not item: hte = " ' @@ -690,15 +690,15 @@ def do_One_Page(title, text: str, item: str = ""): # --- printt(f"**item: {item}") # --- - NewText = make_new_text(item, title, text) + new_text = make_new_text(item, title, text) # --- - if not NewText: + if not new_text: ur = f'{item}.' printo(f"لا توجد نتائج لهذه الصفحة تأكد من صحة معرف ويكي بيانات: {ur}.") return text # --- - if NewText == "nodiff": + if new_text == "nodiff": printo("nodiff") return text # --- - return NewText + return new_text diff --git a/src/cy/jsub.py b/src/cy/jsub.py index 13e1f02..e31881c 100644 --- a/src/cy/jsub.py +++ b/src/cy/jsub.py @@ -1,32 +1,17 @@ #!/usr/bin/python3 """ -tfj run jsubx --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py cy/jsub -ns:10 -cat:تصنيف:سجل_فوز_دراج_من_ويكي_بيانات/قوالب" -python3 core8/pwb.py cy/jsub -page:جيروين_بلايلفينس ask -python3 core8/pwb.py cy/jsub -page:إديتا_بوتشينسكايتي -python3 core8/pwb.py cy/jsub -page: -python3 core8/pwb.py cy/jsub -page:قالب:نتيجة_سباق_الدراجات/ميغيل_إندوراين -python3 core8/pwb.py cy/jsub -page:قالب:نتيجة_سباق_الدراجات/ألبيرتو_كونتادور -python3 core8/pwb.py cy/jsub -page: -python3 core8/pwb.py cy/jsub -page: -python3 core8/pwb.py cy/jsub -page:كريس_فروم -python3 core8/pwb.py cy/jsub -ref:قالب:نتيجة_سباق_الدراجات/بداية -python3 core8/pwb.py cy/jsub -cat: -python3 core8/pwb.py cy/jsub -ns:10 -cat:تصنيف:سجل_فوز_دراج_من_ويكي_بيانات/قوالب -python3 core8/pwb.py cy/jsub -cat: -python3 core8/pwb.py cy/jsub -cat: -python3 core8/pwb.py cy/jsub -cat:تصنيف:سجل_فوز_دراج_من_ويكي_بيانات https://www.wikidata.org/wiki/Wikidata:Pywikibot_-_Python_3_Tutorial/Gathering_data_from_Arabic-Wikipedia """ -import wd_gent -from cy_bot.do_text import do_One_Page - from shared.api_page import load_main_api +from cy.cy_bot.do_text import do_One_Page +from wd_core import wd_gent + skip_titles = [ "قالب:نتيجة سباق الدراجات", "قالب:نتيجة سباق الدراجات/بداية", diff --git a/src/cy/mv.py b/src/cy/mv.py index 9975b1a..b0a2c7d 100644 --- a/src/cy/mv.py +++ b/src/cy/mv.py @@ -18,11 +18,11 @@ import sys import tqdm -import wd_gent import wikitextparser as wtp - from shared.api_page import load_main_api +import wd_gent + logger = logging.getLogger(__name__) diff --git a/src/des/book.py b/src/des/book.py index e7e72b0..d251f72 100644 --- a/src/des/book.py +++ b/src/des/book.py @@ -3,8 +3,6 @@ إضافة وصف للكتب والقصص -python3 core8/pwb.py des/book optional -python3 core8/pwb.py des/book ask python pwb.py des/book @@ -14,9 +12,9 @@ import re import sys -from bots_subs.wd_api import wd_bot -from bots_subs.wd_api.wd_desc import work_api_desc -from bots_subs.wd_api.wd_sparql_bot import sparql_generator_big_results +from wd_api import wd_bot +from wd_api.wd_desc import work_api_desc +from wd_api.wd_sparql_bot import sparql_generator_big_results logger = logging.getLogger(__name__) @@ -66,11 +64,11 @@ } -def one_book_item(Qid, pa, lang, keys) -> None: +def one_book_item(qid_str, pa, lang, keys) -> None: item = wd_bot.Get_Item_API_From_Qid(pa["item"]) if not item: return - # desc = MakeDesc(Qid, auth, lang) + # desc = MakeDesc(qid_str, auth, lang) # Summary= 'Bot: - Add descriptions: '+ lang keys = sorted(keys) # --- @@ -80,7 +78,7 @@ def one_book_item(Qid, pa, lang, keys) -> None: logger.info(f"keys:{str(keys)}") # --- descriptions = item["descriptions"] - NewDesc = {} + new_desc_data = {} addedlangs = [] # --- for lang in keys: @@ -89,8 +87,8 @@ def one_book_item(Qid, pa, lang, keys) -> None: lang2 = lang if lang in ("en-ca", "en-gb"): lang2 = "en" - if des := MakeDesc(Qid, pa, lang2): - NewDesc[lang] = {"language": lang, "value": des} + if des := MakeDesc(qid_str, pa, lang2): + new_desc_data[lang] = {"language": lang, "value": des} dns = "" if "endes" in pa: dns = pa["endes"] @@ -100,20 +98,20 @@ def one_book_item(Qid, pa, lang, keys) -> None: logger.info(f'*no desc for "{lang}"') # --- if addedlangs: - qitem = Qid # item.title(as_link=False) + qitem = qid_str # item.title(as_link=False) if AskSave[1]: logger.info(f"================== + {addedlangs}") - for lan, value in NewDesc.items(): - logger.info(f"""lang:{lan}, value: \"{value['value']}\"""") + for lan, value in new_desc_data.items(): + logger.info(f"""lang:{lan}, value: \"{value["value"]}\"""") saaa = input("<> Add as descriptions? ") if saaa in ["y", "a", ""]: if saaa == "a": AskSave[1] = False - work_api_desc(NewDesc, qitem) + work_api_desc(new_desc_data, qitem) else: logger.info("* rong answer") else: - work_api_desc(NewDesc, qitem) + work_api_desc(new_desc_data, qitem) Comma = { @@ -139,13 +137,13 @@ def one_book_item(Qid, pa, lang, keys) -> None: Comma2 = {"ar": "، و", "en": ", ", "de": ", ", "fr": ", ", "nl": ", "} -def GetQuery(Qid, lang, keys): - P50 = "P175" if Qid == "Q482994" else "P50" +def GetQuery(qid_str, lang, keys): + P50 = "P175" if qid_str == "Q482994" else "P50" # --- # sa = ('?item wdt:P136 wd:Q8261 . ?item wdt:P31* wd:Q7725634 .\n') - sa = f"?item wdt:P31 wd:{Qid} .\n" + sa = f"?item wdt:P31 wd:{qid_str} .\n" # --- - if Qid == "novel": + if qid_str == "novel": sa = "?item wdt:P136 wd:Q8261 . ?item wdt:P31 wd:Q7725634 .\n" # --- ur = f'SELECT ?item (GROUP_CONCAT(DISTINCT(?auth{lang}); separator="{Comma[lang]}") as ?{lang}) ' @@ -200,22 +198,22 @@ def Gquery2(json1): Off[1] = int(value) -def WorkWithOneLang(Qid, lang, keys) -> None: +def WorkWithOneLang(qid_str, lang, keys) -> None: logger.info("*<> WorkWithOneLang: ") # --- - query = GetQuery(Qid, lang, keys) + query = GetQuery(qid_str, lang, keys) # --- PageList = sparql_generator_big_results(query, offset=Off[1], limit=limit[1], alllimit=0) # --- logger.info("* PageList: ") - SAO = Qlist[Qid][lang] + SAO = Qlist[qid_str][lang] # --- total = len(PageList) # --- for num, pa in enumerate(PageList, start=1): pa["item"] = pa["item"].split("/entity/")[1] - logger.info(f"<>> {lang} \"{SAO}\" :{num}/{total} : {pa['item']}") - one_book_item(Qid, pa, lang, keys) + logger.info(f'<>> {lang} "{SAO}" :{num}/{total} : {pa["item"]}') + one_book_item(qid_str, pa, lang, keys) by_list = { @@ -238,7 +236,7 @@ def WorkWithOneLang(Qid, lang, keys) -> None: } -def MakeDesc(Qid, pa, lang): +def MakeDesc(qid, pa, lang): # for lang in language: # auth description = False @@ -249,12 +247,12 @@ def MakeDesc(Qid, pa, lang): if lang not in by_list: logger.info(f'<>> cant find "by" in by_list for lang: "{lang}"') return False - co = "من أداء " if (Qid == "Q482994") and (lang == "ar") else f"{by_list[lang]} " + co = "من أداء " if (qid == "Q482994") and (lang == "ar") else f"{by_list[lang]} " # --- if (lang in pa) and (pa[lang] != ""): if auth := pa[lang]: - if lang in Qlist[Qid]: - des = Qlist[Qid][lang] + if lang in Qlist[qid]: + des = Qlist[qid][lang] d = des # الوصف # d = d + ' ' # الرابط by d = f"{d} {co}" @@ -285,18 +283,18 @@ def main() -> None: AskSave[1] = False logger.info("start with query") # --- - for Queries, Qid in enumerate(Qlist, start=1): - keys = Qlist[Qid].keys() + for Queries, qid_str in enumerate(Qlist, start=1): + keys = Qlist[qid_str].keys() keys = ["ar"] - totalqueries = len(Qlist.keys()) * len(Qlist[Qid].keys()) - logger.info(f'*Qid "{Qid}":') - out = f"<> *== Quary:\"{Qlist[Qid]['ar']}\", {Queries}/{totalqueries}. ==" + totalqueries = len(Qlist.keys()) * len(Qlist[qid_str].keys()) + logger.info(f'*qid_str "{qid_str}":') + out = f'<> *== Quary:"{Qlist[qid_str]["ar"]}", {Queries}/{totalqueries}. ==' logger.info(out) - # logger.info( 'lab: "%s". ' % Qlist[Qid]['ar'] ) + # logger.info( 'lab: "%s". ' % Qlist[qid_str]['ar'] ) for lang in keys: - # logger.info( Qlist[Qid][lang] ) - WorkWithOneLang(Qid, lang, keys) + # logger.info( Qlist[qid_str][lang] ) + WorkWithOneLang(qid_str, lang, keys) if __name__ == "__main__": diff --git a/src/des/desc.py b/src/des/desc.py index a575209..4b4f7af 100644 --- a/src/des/desc.py +++ b/src/des/desc.py @@ -2,24 +2,10 @@ """ #!/usr/bin/env python3 -python3 core8/pwb.py des/desc limit:1000 optional -python3 core8/pwb.py des/desc limit:1000 optional place:Q173387 save #قبر -python3 core8/pwb.py des/desc limit:1000 optional place:Q918230 save #فيلا رومانية -python3 core8/pwb.py des/desc limit:1000 optional place:Q641226 #صالة -python3 core8/pwb.py des/desc limit:1000 optional place:Q483110 #ملعب -python3 core8/pwb.py des/desc limit:1000 optional place:Q1329623 #مركز ثقافي -python3 core8/pwb.py des/desc limit:1000 optional place:Q1154710 #استاد كرة قدم -python3 core8/pwb.py des/desc limit:1000 optional place:Q12518 #برج -python3 core8/pwb.py des/desc limit:1000 optional place:Q2225692 #منطقة سكنية في أندونوسيا -python3 core8/pwb.py des/desc limit:1000 optional place:Q185113 أوصاف مناطق جغرافية -python3 core8/pwb.py des/desc limit:2000 offplace:85 -python3 core8/pwb.py des/desc limit:2000 offplace:100 qslimit:5000 -python3 core8/pwb.py des/desc limit:2000 qslimit:2000 alllimit:10000 -python3 core8/pwb.py des/desc limit:2000 qslimit:5000 alllimit:10000 SELECT DISTINCT (GROUP_CONCAT(DISTINCT(STRAFTER(STR(?item), "/entity/")); separator="@@") as ?q) #(CONCAT(STRAFTER(STR(?item), "/entity/")) AS ?q) @@ -46,22 +32,22 @@ import re import sys -from bots_subs.hi_api import HimoAPIBot -from bots_subs.qs_bot import QS_line -from bots_subs.wd_api import wd_bot -from bots_subs.wd_api.wd_sparql_bot import sparql_generator_big_results -from des.contries2 import ContriesTable2 -from des.places import placesTable - from shared.api_page import load_main_api +from shared.himo_api import HimoAPIBot +from shared.qs_bot import QS_line +from wd_api import wd_bot +from wd_api.wd_sparql_bot import sparql_generator_big_results + +from des.contries2 import ContriesTable2 +from des.places import PLACES_TABLE -WD_API_Bot = HimoAPIBot(mr_or_bot="bot", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="bot", www="www") logger = logging.getLogger(__name__) -# placesTable = {"Q29701762": {"ar": "مستوطنة"}} -placestable2 = {fg: placesTable[fg] for fg in placesTable} +# PLACES_TABLE = {"Q29701762": {"ar": "مستوطنة"}} +placestable2 = {fg: PLACES_TABLE[fg] for fg in PLACES_TABLE} q_list_done = [] New_QS = {1: []} @@ -130,10 +116,8 @@ elif arg == "offplace": offset_place[1] = int(value) # --- - # python3 core8/pwb.py des/desc descqs limit:4000 optional place:Q185113 - # python3 core8/pwb.py des/desc descqs limit:1000 place:Q8054 - if arg == "place" and value in placesTable: - placestable2 = {value: placesTable[value]} + if arg == "place" and value in PLACES_TABLE: + placestable2 = {value: PLACES_TABLE[value]} # --- if arg == "alllimit": alllimit[1] = int(value) @@ -144,7 +128,7 @@ # --- -def get_property_label_for_qids(properties, List): +def get_property_label_for_qids(properties, list_data): # --- # logger.info('start get_property_label_for_qids:' ) # --- @@ -152,7 +136,7 @@ def get_property_label_for_qids(properties, List): # --- num = 0 # --- - for qid in List: + for qid in list_data: num += 1 lino = "{{" lino += f"subst:user:Mr._Ibrahem/line2|{qid}" @@ -208,7 +192,7 @@ def Add_desc(q, value, lang) -> str: if "descqs" in sys.argv: descqs(q, value, lang) else: - WD_API_Bot.Des_API(q, value, lang, ask="") + WdApiBot.des_api(q, value, lang, ask="") def work_one_item(start, lang, tab, c, total: int, findlab: bool = False) -> str: diff --git a/src/des/fam.py b/src/des/fam.py index 8deb0cf..b6f2c4b 100644 --- a/src/des/fam.py +++ b/src/des/fam.py @@ -3,10 +3,6 @@ # """ جميع الأوصاف -python3 core8/pwb.py des/fam Q55678 -python3 core8/pwb.py des/fam Q7889 -python3 core8/pwb.py des/fam Q318 -python3 core8/pwb.py des/fam """ @@ -15,7 +11,8 @@ import sys import tqdm -from bots_subs.wd_api import newdesc, wd_sparql_bot +from wd_api import newdesc, wd_sparql_bot + from des.railway import railway_tables, work_railway from desc_dicts.descraptions import ( DescraptionsTable, @@ -26,7 +23,7 @@ logger = logging.getLogger(__name__) -desc_table = { +DESC_TABLE = { "Q318": Space_Descraptions.get("Q318", {}), "Q523": Space_Descraptions.get("Q523", {}), "Q3863": Space_Descraptions.get("Q3863", {}), @@ -64,30 +61,30 @@ "Q15145755": DescraptionsTable.get("Wikimedia module", {}), # Module test cases "Q18711811": DescraptionsTable.get("Wikimedia module", {}), # map data module "Q24046192": DescraptionsTable.get("Wikimedia category", {}), - # 'Q8502' : placesTable.get('Q8502', {}), # جبل - # 'Q39614' : placesTable.get('Q39614', {}), # مقبرة - # 'Q79007' : placesTable.get('Q79007', {}), # شارع + # 'Q8502' : PLACES_TABLE.get('Q8502', {}), # جبل + # 'Q39614' : PLACES_TABLE.get('Q39614', {}), # مقبرة + # 'Q79007' : PLACES_TABLE.get('Q79007', {}), # شارع } -desc_table["Q726242"] = {"ar": "نجم"} -desc_table["Q2247863"] = {"ar": "نجم"} -desc_table["Q66619666"] = {"ar": "نجم"} -desc_table["Q72803622"] = {"ar": "نجم"} +DESC_TABLE["Q726242"] = {"ar": "نجم"} +DESC_TABLE["Q2247863"] = {"ar": "نجم"} +DESC_TABLE["Q66619666"] = {"ar": "نجم"} +DESC_TABLE["Q72803622"] = {"ar": "نجم"} for x, dd in railway_tables.items(): - desc_table[x] = dd + DESC_TABLE[x] = dd -for x in desc_table: +for x in DESC_TABLE: if x in sys.argv: - desc_table = {x: desc_table[x]} + DESC_TABLE = {x: DESC_TABLE[x]} break temp_table = {} -if len(desc_table) > 1: - # chose randomly 5 of the desc_table +if len(DESC_TABLE) > 1: + # chose randomly 5 of the DESC_TABLE # --- - liste = list(desc_table.keys()) + liste = list(DESC_TABLE.keys()) # --- list2 = random.sample(liste, 10) # --- @@ -96,9 +93,9 @@ random.shuffle(list2) # --- for x in list2: - temp_table[x] = desc_table[x] + temp_table[x] = DESC_TABLE[x] # --- - desc_table = temp_table + DESC_TABLE = temp_table quarry_o = """ SELECT DISTINCT ?item ?langs @@ -150,10 +147,10 @@ def work_one_json(json1, topic_ar, p31, p31_langs) -> None: # --- if p31 in railway_tables: work_railway({}, p31, q=q) - # elif p31 in placesTable: + # elif p31 in PLACES_TABLE: # work_railway( {}, p31, q=q ) else: - newdesc.work22(q, p31, desc_table) + newdesc.work22(q, p31, DESC_TABLE) def work_one_quarry(quarry, p31, p31_desc): @@ -171,12 +168,12 @@ def work_one_quarry(quarry, p31, p31_desc): def main() -> None: - # lenth of desc_table and quarry_list - all_lenth = len(quarry_list) * len(desc_table) + # lenth of DESC_TABLE and quarry_list + all_lenth = len(quarry_list) * len(DESC_TABLE) # --- numb = 0 # --- - for p31, p31_desc in desc_table.items(): + for p31, p31_desc in DESC_TABLE.items(): # --- quarry_result_lenth = 0 # --- diff --git a/src/des/film.py b/src/des/film.py index d6b6bad..80d2b01 100644 --- a/src/des/film.py +++ b/src/des/film.py @@ -12,8 +12,8 @@ import re import pywikibot -from bots_subs.wd_api import wd_sparql_bot -from bots_subs.wd_api.wd_desc import work_api_desc +from wd_api import wd_sparql_bot +from wd_api.wd_desc import work_api_desc logger = logging.getLogger(__name__) @@ -22,14 +22,14 @@ AskSave = {1: True} -# def AddDes( item , pa , lang , Qid , keys): +# def AddDes( item , pa , lang , qid_str , keys): -def one_film_item(Qid, pa, lang, keys) -> None: +def one_film_item(qid_str, pa, lang, keys) -> None: item = getwditem(pa["item"]) if not item: return - # desc = MakeDesc(Qid, auth, lang) + # desc = MakeDesc(qid_str, auth, lang) # Summary= 'Bot: - Add descriptions: '+ lang keys = sorted(keys) # --- @@ -37,7 +37,7 @@ def one_film_item(Qid, pa, lang, keys) -> None: logger.info(f"keys:{str(keys)}") # --- descriptions = item.descriptions - NewDesc = {} + new_desc_data = {} addedlangs = [] # --- for lang in keys: @@ -46,9 +46,9 @@ def one_film_item(Qid, pa, lang, keys) -> None: lang2 = lang # --- - if MakeDesc(Qid, pa, lang2): - des = MakeDesc(Qid, pa, lang2) - NewDesc[lang] = {"language": lang, "value": des} + if MakeDesc(qid_str, pa, lang2): + des = MakeDesc(qid_str, pa, lang2) + new_desc_data[lang] = {"language": lang, "value": des} dns = "" if "endes" in pa: dns = pa["endes"] @@ -61,17 +61,17 @@ def one_film_item(Qid, pa, lang, keys) -> None: qitem = item.title(as_link=False) if AskSave[1]: logger.info(f"================== + {addedlangs}") - for lan, value in NewDesc.items(): - logger.info(f"""lang:{lan}, value: \"{value['value']}\"""") + for lan, value in new_desc_data.items(): + logger.info(f"""lang:{lan}, value: \"{value["value"]}\"""") saaa = input(" Add as descriptions? ") if saaa in ["y", "a", ""]: if saaa == "a": AskSave[1] = False - work_api_desc(NewDesc, qitem) + work_api_desc(new_desc_data, qitem) else: logger.info("* rong answer") else: - work_api_desc(NewDesc, qitem) + work_api_desc(new_desc_data, qitem) def getwditem(qitem): @@ -106,7 +106,7 @@ def getwditem(qitem): Comma2 = {"ar": "، و", "en": ", ", "de": ", ", "fr": ", ", "nl": ", "} -def GetQuery(Qid, lang, keys): +def GetQuery(qid_str, lang, keys): # --- P50 = "P57" # --- @@ -202,7 +202,7 @@ def Gquery2(json1): """ -def WorkWithOneLang(Qid, lang, keys) -> None: +def WorkWithOneLang(qid_str, lang, keys) -> None: logger.info("*<> WorkWithOneLang: ") limit = 200 # limit = '10000' @@ -211,7 +211,7 @@ def WorkWithOneLang(Qid, lang, keys) -> None: # try: # --- quary = quaua - # quary = GetQuery(Qid , lang, keys) + # quary = GetQuery(qid_str , lang, keys) quary = quary + "\n limit %d" % limit logger.info(quary) # --- @@ -223,10 +223,10 @@ def WorkWithOneLang(Qid, lang, keys) -> None: for num, pa in enumerate(PageList.keys(), start=1): logger.info(pa) PageList[pa]["item"] = pa.split("/entity/")[1] - SAO = filmform[Qid][lang] + SAO = filmform[qid_str][lang] logger.info("<>> %s (%s) :%s/%d : %s" % (lang, SAO, num, total, PageList[pa]["item"])) # --- - one_film_item(Qid, PageList[pa], lang, keys) + one_film_item(qid_str, PageList[pa], lang, keys) by_list = { @@ -249,7 +249,7 @@ def WorkWithOneLang(Qid, lang, keys) -> None: } -def MakeDesc(Qid, pa, lang): +def MakeDesc(qid, pa, lang): # for lang in language: # auth description = False @@ -260,12 +260,12 @@ def MakeDesc(Qid, pa, lang): if lang not in by_list: logger.info(f'<>> cant find "by" in by_list for lang: "{lang}"') return False - "من أداء " if (Qid == "Q482994") and (lang == "ar") else f"{by_list[lang]} " + "من أداء " if (qid == "Q482994") and (lang == "ar") else f"{by_list[lang]} " # --- if (lang in pa) and (pa[lang] != ""): if auth := pa[lang]: - if lang in filmform[Qid]: - des = filmform[Qid][lang] + if lang in filmform[qid]: + des = filmform[qid][lang] YEAR = pa["dates"] YEARS = YEAR # .split(',') endes = pa["endes"][0] diff --git a/src/des/galaxy.py b/src/des/galaxy.py index 34d88b8..77a3f11 100644 --- a/src/des/galaxy.py +++ b/src/des/galaxy.py @@ -9,11 +9,11 @@ """ +from wd_api import newdesc -from bots_subs.wd_api import newdesc from desc_dicts.descraptions import DescraptionsTable, Qid_Descraptions -# newdesc.mainfromQuarry2( topic , Quarry, translations) +# newdesc.mainfromQuarry2( topic , quarry, translations) translations = {"Q318": DescraptionsTable.get("galaxy") or Qid_Descraptions.get("Q318") or {}} diff --git a/src/des/na.py b/src/des/na.py index 484d9a1..a7dcf12 100644 --- a/src/des/na.py +++ b/src/des/na.py @@ -5,18 +5,17 @@ """ - import logging import re import sys -from bots_subs.hi_api import HimoAPIBot -from bots_subs.wd_api import wd_sparql_bot +from shared.himo_api import HimoAPIBot +from wd_api import wd_sparql_bot logger = logging.getLogger(__name__) -WD_API_Bot = HimoAPIBot(mr_or_bot="mr", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="mr", www="www") bylangs = False # False#True @@ -45,7 +44,7 @@ def action(json1) -> None: logger.info(f' * ar_lab:"{ar_lab}",en_name:"{en_name}"') c += 1 logger.info(f' * action {c}/{total} "{q}"') - WD_API_Bot.Labels_API(q, ar_lab, "ar", False, Or_Alii=True) + WdApiBot.Labels_API(q, ar_lab, "ar", False, or_alii=True) else: logger.info(f" <> * q in items_done. {q}") @@ -74,8 +73,8 @@ def make_quarry(ar_suff: str = "", item_p31_cat: str = "", en_suff: str = "", en return quaaa -Quarry = { - "items": """# تسمية عناصر طبقاً لاسم التصنيف +quarry = { + "items1": """# تسمية عناصر طبقاً لاسم التصنيف SELECT DISTINCT #?item ?label ?cat_ar (concat("" , strafter(str(?item),"/entity/") , "") as ?item_q) (concat( (strafter(str(?cat_ar),"تصنيف:")) ) as ?ar_name) @@ -255,12 +254,12 @@ def main() -> None: logger.info(f"<>>> limit ( {value} ) ") limits[1] = value # --- - if arg in Quarry: - logger.info(f"<>>> use Quarry:{arg} . ") - qya[arg] = Quarry[arg] + if arg in quarry: + logger.info(f"<>>> use quarry:{arg} . ") + qya[arg] = quarry[arg] # --- if not qya: - qya = Quarry + qya = quarry for number, key in enumerate(qya, start=1): quuu = qya[key] for arg in sys.argv: diff --git a/src/des/numb.py b/src/des/numb.py index 2b075b6..b06253a 100644 --- a/src/des/numb.py +++ b/src/des/numb.py @@ -1,18 +1,14 @@ #!/usr/bin/python3 -""" - -python3 core8/pwb.py des/numb - -""" +""" """ import logging -from bots_subs.hi_api import HimoAPIBot -from bots_subs.wd_api import wd_bot, wd_sparql_bot +from shared.himo_api import HimoAPIBot +from wd_api import wd_bot, wd_sparql_bot logger = logging.getLogger(__name__) -WD_API_Bot = HimoAPIBot(mr_or_bot="bot", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="bot", www="www") limit = {1: 0} @@ -26,8 +22,8 @@ json1 = wd_sparql_bot.sparql_generator_url(quarry) total = len(json1) for c, q in enumerate(json1, start=1): - Qid = q["q"] - logger.info(f"work {c} from {total} , {Qid}") - descriptions = wd_bot.Get_item_descriptions_or_labels(Qid, "descriptions") + qid_str = q["q"] + logger.info(f"work {c} from {total} , {qid_str}") + descriptions = wd_bot.Get_item_descriptions_or_labels(qid_str, "descriptions") if "ar" not in descriptions: - WD_API_Bot.Des_API(Qid, "عدد أولي", "ar", ask="") + WdApiBot.des_api(qid_str, "عدد أولي", "ar", ask="") diff --git a/src/des/places.py b/src/des/places.py index a5e5c83..72df0ed 100644 --- a/src/des/places.py +++ b/src/des/places.py @@ -138,7 +138,7 @@ """ -placesTable = { +PLACES_TABLE = { "Q108325": {"ar": "مصلى كنسي"}, "Q1093829": {"ar": "مدينة"}, "Q1115575": {"ar": "أبرشية مدنية"}, @@ -336,31 +336,31 @@ "Q569500": {"ar": "مركز صحي", "en": ""}, "Q39614": {"ar": "مقبرة", "en": "cemetery"}, } -placesTable["Q8054"] = {"ar": "بروتين"} +PLACES_TABLE["Q8054"] = {"ar": "بروتين"} -placesTable["Q207524"] = {"ar": "جزيرة صغيرة", "en": "islet"} -placesTable["Q22698"] = {"ar": "متنزه", "en": "park"} -# placesTable["Q34795826"] = { "ar" : "" , "en" : "moor" } -placesTable["Q211748"] = {"ar": "حقل نفط", "en": "oilfield"} +PLACES_TABLE["Q207524"] = {"ar": "جزيرة صغيرة", "en": "islet"} +PLACES_TABLE["Q22698"] = {"ar": "متنزه", "en": "park"} +# PLACES_TABLE["Q34795826"] = { "ar" : "" , "en" : "moor" } +PLACES_TABLE["Q211748"] = {"ar": "حقل نفط", "en": "oilfield"} -placesTable["Q1248784"] = {"ar": "مطار", "en": "airport"} -# placesTable["Q591942"] = { "ar" : "فرع" , "en" : "distributary" } -placesTable["Q105190"] = {"ar": "سد مائي", "en": "levee"} -placesTable["Q532"] = {"ar": "قرية", "en": "village"} -placesTable["Q820477"] = {"ar": "منجم", "en": "mine"} +PLACES_TABLE["Q1248784"] = {"ar": "مطار", "en": "airport"} +# PLACES_TABLE["Q591942"] = { "ar" : "فرع" , "en" : "distributary" } +PLACES_TABLE["Q105190"] = {"ar": "سد مائي", "en": "levee"} +PLACES_TABLE["Q532"] = {"ar": "قرية", "en": "village"} +PLACES_TABLE["Q820477"] = {"ar": "منجم", "en": "mine"} -placesTable["Q46831"] = {"ar": "سلسلة جبلية", "en": "mountains"} -placesTable["Q150784"] = {"ar": "أخدود", "en": "canyon"} -placesTable["Q27590"] = {"ar": "براح", "en": "heath"} -placesTable["Q37901"] = {"ar": "مضيق", "en": "strait"} -placesTable["Q107679"] = {"ar": "جرف", "en": "cliff"} -placesTable["Q170321"] = {"ar": "منطقة رطبة", "en": "wetland"} -placesTable["Q75520"] = {"ar": "هضبة", "en": "plateau"} -placesTable["Q2935978"] = {"ar": "قناة ري", "en": "irrigation canal"} -placesTable["Q190429"] = {"ar": "منخفض", "en": "depression"} -placesTable["Q44782"] = {"ar": "ميناء", "en": "port"} -# placesTable[""] = { "ar" : "" , "en" : "" } -# placesTable[""] = { "ar" : "" , "en" : "" } -# placesTable[""] = { "ar" : "" , "en" : "" } -# placesTable[""] = { "ar" : "" , "en" : "" } -placesTable["Q34379419"] = {"ar": "منطقة رملية", "en": "sand area"} +PLACES_TABLE["Q46831"] = {"ar": "سلسلة جبلية", "en": "mountains"} +PLACES_TABLE["Q150784"] = {"ar": "أخدود", "en": "canyon"} +PLACES_TABLE["Q27590"] = {"ar": "براح", "en": "heath"} +PLACES_TABLE["Q37901"] = {"ar": "مضيق", "en": "strait"} +PLACES_TABLE["Q107679"] = {"ar": "جرف", "en": "cliff"} +PLACES_TABLE["Q170321"] = {"ar": "منطقة رطبة", "en": "wetland"} +PLACES_TABLE["Q75520"] = {"ar": "هضبة", "en": "plateau"} +PLACES_TABLE["Q2935978"] = {"ar": "قناة ري", "en": "irrigation canal"} +PLACES_TABLE["Q190429"] = {"ar": "منخفض", "en": "depression"} +PLACES_TABLE["Q44782"] = {"ar": "ميناء", "en": "port"} +# PLACES_TABLE[""] = { "ar" : "" , "en" : "" } +# PLACES_TABLE[""] = { "ar" : "" , "en" : "" } +# PLACES_TABLE[""] = { "ar" : "" , "en" : "" } +# PLACES_TABLE[""] = { "ar" : "" , "en" : "" } +PLACES_TABLE["Q34379419"] = {"ar": "منطقة رملية", "en": "sand area"} diff --git a/src/des/railway.py b/src/des/railway.py index af86c0f..552aa27 100644 --- a/src/des/railway.py +++ b/src/des/railway.py @@ -3,17 +3,14 @@ """ from des.railway import railway_tables, work_railway#work_railway( item, P31, q='' ) -python3 core8/pwb.py des/fam railway Q55678 -python3 core8/pwb.py des/fam railway Q728937 -python3 core8/pwb.py des/fam railway Q784159 -python3 core8/pwb.py des/fam railway Q55488 """ # import sys -from bots_subs.wd_api import wd_bot -from bots_subs.wd_api.wd_desc import work_api_desc +from wd_api import wd_bot +from wd_api.wd_desc import work_api_desc + from des.ru_st_2_latin import make_en_label # enlabel = make_en_label(labels, Add=False) @@ -26,11 +23,11 @@ } -def Get_P_API_id(claims, P, onlyone: bool = False): +def Get_P_API_id(claims, pid, onlyone: bool = False): # --- lista = [] # --- - for c in claims.get(P, {}): + for c in claims.get(pid, {}): q = c.get("mainsnak", {}).get("datavalue", {}).get("value", {}).get("id") if q: lista.append(q) @@ -55,7 +52,7 @@ def work_railway(wditem, p31, q: str = ""): labels = wditem.get("labels", {}) if labels.get("en", "") == "": print("item enlabel == ''") - make_en_label(labels, q, Add=True) + make_en_label(labels, q, add_it=True) # --- Claims = wditem.get("claims", {}) # --- @@ -93,7 +90,7 @@ def work_railway(wditem, p31, q: str = ""): "p131": {"ar": p131_labels.get("ar", ""), "en": p131_labels.get("en", "")}, } # --- - P31_list = Get_P_API_id(Claims, "P31") + p31_list = Get_P_API_id(Claims, "P31") # --- for lang, des in to_do_descs.items(): if not des: @@ -126,7 +123,7 @@ def work_railway(wditem, p31, q: str = ""): # --- desc_n = des if p17_desc: - if p31 != "Q728937" and "Q728937" not in P31_list and p131_desc: + if p31 != "Q728937" and "Q728937" not in p31_list and p131_desc: desc_n = lang_format[lang][2].format(des, p131_desc, p17_desc) else: desc_n = lang_format[lang][1].format(des, p17_desc) diff --git a/src/des/ru_st_2_latin.py b/src/des/ru_st_2_latin.py index e04d93c..d245fa1 100644 --- a/src/des/ru_st_2_latin.py +++ b/src/des/ru_st_2_latin.py @@ -3,17 +3,16 @@ from des.ru_st_2_latin import make_en_label # enlabel = make_en_label(labels, q, Add=False) -python3 core8/pwb.py des/ru_st_2_latin test """ import sys import pywikibot -from bots_subs.hi_api import HimoAPIBot from pywikibot.pagegenerators import WikidataSPARQLPageGenerator +from shared.himo_api import HimoAPIBot -WD_API_Bot = HimoAPIBot(mr_or_bot="bot", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="bot", www="www") letters_to_latin = { "ru": { @@ -299,7 +298,7 @@ def add_new_label(q, enlabel: str) -> None: # --- data = {"labels": labels} # --- - WD_API_Bot.New_Mult_Des(q, data, "Bot: cyrillic2latin-labels", False) + WdApiBot.New_Mult_Des(q, data, "Bot: cyrillic2latin-labels", False) # abcd = "abcdefghijklmnopqrstuvwxyz".split('') @@ -331,7 +330,7 @@ def change_one_lab(text: str, lang): return new_lab -def make_en_label(labels: str, q, Add: bool = False): +def make_en_label(labels: str, q, add_it: bool = False): org_lab = "" new_lab = "" # --- @@ -345,7 +344,7 @@ def make_en_label(labels: str, q, Add: bool = False): break # --- if new_lab: - if Add: + if add_it: add_new_label(q, new_lab) # --- return new_lab diff --git a/src/desc_dicts/descraptions.py b/src/desc_dicts/descraptions.py index 1e50ea7..6cfd833 100644 --- a/src/desc_dicts/descraptions.py +++ b/src/desc_dicts/descraptions.py @@ -60,7 +60,7 @@ "Q820655": { "ar": "قانون تشريعي", "en": "statute", - }, # python3 core8/pwb.py np/nldes3 sparql:Q820655 + }, "Q207694": {"ar": "متحف فني", "en": "art museum"}, "Q27032363": {"ar": "أرشيف صور", "en": "photo archive"}, "Q7187": {"ar": "جين", "en": "gene"}, diff --git a/src/desc_dicts/descraptions_dict_new.py b/src/desc_dicts/descraptions_dict_new.py index f5762a8..2ff63e8 100644 --- a/src/desc_dicts/descraptions_dict_new.py +++ b/src/desc_dicts/descraptions_dict_new.py @@ -7,7 +7,8 @@ from pathlib import Path from desc_dicts.descraptions_dict import many_lang_qid_desc, replace_desc -from wd_utils.utils import load_data_from_url, open_file_json_check_time, save_json_data + +from .utils import load_data_from_url, open_file_json_check_time, save_json_data logger = logging.getLogger(__name__) diff --git a/src/desc_dicts/taxones.py b/src/desc_dicts/taxones.py index 42c1548..648e7fb 100644 --- a/src/desc_dicts/taxones.py +++ b/src/desc_dicts/taxones.py @@ -1,8 +1,7 @@ #!/usr/bin/python3 """ """ - -tax_translations = { +TAX_TRANSLATIONS = { "Branch of": "فرع من", "Capaxorder of": "رتبة كبرى من", "Class of": "طائفة من", @@ -75,7 +74,7 @@ "Variety of": "ضَرْب من", } -taxone_list = { +TAXONE_LIST = { "~ isopod": "~ متماثلات الأرجل", "~ alga": "~ الطحالب", "~ algae": "~ الطحالب", @@ -129,7 +128,7 @@ "~ worms": "~ الديدان", } -lab_for_p171 = { +LAB_FOR_P171 = { "Q1390": "من الحشرات", "Q5113": "من الطيور", "Q10908": "من البرمائيات", @@ -272,7 +271,7 @@ "Q11937877": "من القشريات المتعددة", } -labforP105 = { +LAB_FOR_P105 = { "Q7432": "نوع", "Q34740": "جنس", "Q68947": "نويع", diff --git a/src/desc_dicts/tiny_wrwr.py b/src/desc_dicts/tiny_wrwr.py index 9bd05f5..a670e9d 100644 --- a/src/desc_dicts/tiny_wrwr.py +++ b/src/desc_dicts/tiny_wrwr.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 """ """ + from desc_dicts.descraptions import Qid_Desc tiny_wrwr = { diff --git a/src/nep/bots/helps.py b/src/nep/bots/helps.py index 85af8d9..ab151fe 100644 --- a/src/nep/bots/helps.py +++ b/src/nep/bots/helps.py @@ -1,9 +1,5 @@ """ Import the traceback and pywikibot modules to handle exceptions. - -Usage: - -from nep.bots.helps import Get_P_API_id, Get_P_API_time, log_new_types, get_female_for_p17, Get_label, get_label_txt, get_lng_description, Get_label_from_item, get_mainsnak """ import json @@ -12,7 +8,8 @@ import sys from pathlib import Path -from bots_subs.wd_api import wd_bot +from wd_api import wd_bot + from nep.others import read_json from nep.tables.cash import labels_cach from nep.tables.nats import nationalities @@ -23,11 +20,11 @@ lng_canbeused = [] -def Get_P_API_id(item, P): +def Get_P_API_id(item, pid): # --- # q = 'claims' in item and item['claims'][P]['mainsnak']['datavalue']['value']['id'] or False lista = [] - claims = item.get("claims", {}).get(P, {}) + claims = item.get("claims", {}).get(pid, {}) for c in claims: if q := c.get("mainsnak", {}).get("datavalue", {}).get("value", {}).get("id", False): lista.append(q) @@ -35,12 +32,12 @@ def Get_P_API_id(item, P): return lista -def Get_P_API_time(item, P): +def Get_P_API_time(item, pid): qlist = [] # --- if not item or not isinstance(item, dict): return False - claims = item.get("claims", {}).get(P, []) + claims = item.get("claims", {}).get(pid, []) for PP31 in claims: vv = PP31.get("mainsnak", {}).get("datavalue", {}).get("value", {}) if isinstance(vv, dict) and vv.get("time"): diff --git a/src/nep/bots/its.py b/src/nep/bots/its.py index 9e8b017..0794ae6 100644 --- a/src/nep/bots/its.py +++ b/src/nep/bots/its.py @@ -1,10 +1,9 @@ -""" -from nep.bots.its import its_a_composition, its_a_computergame, its_a_discography, its_a_fictional_character, its_a_film, its_a_generalthing, its_a_headquarted_thing, its_a_p50, its_a_publication, its_a_sports_season, its_a_tabon_in_thailand, its_a_taxon, its_a_thing_located_in_country, its_an_audio_drama, its_an_episode, its_canton_of_France, its_something_in_a_country, its_something_in_an_entity, its_songs -""" +""" """ import logging -from bots_subs.wd_api import wd_bot +from wd_api import wd_bot + from nep.bots.helps import ( Get_label, Get_label_from_item, diff --git a/src/nep/bots/scientific_article.py b/src/nep/bots/scientific_article.py index dcd4b4f..46e319c 100644 --- a/src/nep/bots/scientific_article.py +++ b/src/nep/bots/scientific_article.py @@ -4,10 +4,12 @@ from nep.bots.scientific_article import make_scientific_article """ + import logging import re import dateutil.parser + from desc_dicts.descraptions_dict import Scientific_descraptions from nep.bots.helps import Get_P_API_time @@ -287,7 +289,7 @@ def make_scientific_desc(lang, date, precision): return desc -def make_scientific_article(item, p31, num: int, TestTable: bool = False): +def make_scientific_article(item, p31, num: int, testtable: bool = False): # --- tablem = {"descriptions": {}, "qid": "", "fixlang": []} # --- @@ -323,13 +325,13 @@ def make_scientific_article(item, p31, num: int, TestTable: bool = False): if desc: translations[lang] = desc # --- - if TestTable: - logger.info(f'<> {translations["en"]}:{translations["da"]}') + if testtable: + logger.info(f"<> {translations['en']}:{translations['da']}") logger.info(translations["en"]) logger.info(translations["da"]) logger.info(translations["ar"]) # --- - NewDesc = {} + new_desc_data = {} addedlangs = [] replacelang = [] # --- @@ -347,7 +349,7 @@ def make_scientific_article(item, p31, num: int, TestTable: bool = False): _ar_descs = ["مقالة علمية", "مقالة بحثية"] # --- if lang not in item_descriptions.keys(): - NewDesc[lang] = {"language": lang, "value": lang_e} + new_desc_data[lang] = {"language": lang, "value": lang_e} addedlangs.append(lang) # --- # elif item_desc == ses_desc or (lang == "ar" and item_desc in ar_descs): # or (lang == "bn" and ): # to fix bn descraptions @@ -359,20 +361,20 @@ def make_scientific_article(item, p31, num: int, TestTable: bool = False): lang_e = lang_e.replace("scholarly article", item_desc) # --- logger.info(f'<> replace desc "{item_desc}"@{lang}. by :{lang_e}') - NewDesc[lang] = {"language": lang, "value": lang_e} + new_desc_data[lang] = {"language": lang, "value": lang_e} addedlangs.append(lang) # --- # fix some error elif pubdate["month"] == "11" and lang in Month_Table: if item_desc.find(Month_Table[lang]["12"]) != -1: logger.info(f'<> find error desc "{item_desc}"@{lang}.') - NewDesc[lang] = {"language": lang, "value": lang_e} + new_desc_data[lang] = {"language": lang, "value": lang_e} replacelang.append(lang) # --- - # logger.info( '<> make_scientific_article' + str(NewDesc) ) + # logger.info( '<> make_scientific_article' + str(new_desc_data) ) if addedlangs or replacelang: # logger.info( '<> **%d: make_scientific_article: %s %s' %(num , item["q"] , p31)) - tablem["descriptions"] = NewDesc + tablem["descriptions"] = new_desc_data tablem["qid"] = q tablem["fixlang"] = replacelang else: diff --git a/src/nep/bots/tax_desc.py b/src/nep/bots/tax_desc.py index 5d566dc..9051594 100644 --- a/src/nep/bots/tax_desc.py +++ b/src/nep/bots/tax_desc.py @@ -1,25 +1,25 @@ #!/usr/bin/python3 -""" -from nep.bots.tax_desc import work_taxon_desc -""" +""" """ + import logging import sys -from bots_subs.hi_api import HimoAPIBot -from bots_subs.wd_api import wd_sparql_bot -from desc_dicts.taxones import lab_for_p171, labforP105, tax_translations, taxone_list +from shared.himo_api import HimoAPIBot +from wd_api import wd_sparql_bot + +from desc_dicts.taxones import LAB_FOR_P105, LAB_FOR_P171, TAX_TRANSLATIONS, TAXONE_LIST from nep.bots.helps import Get_P_API_id logger = logging.getLogger(__name__) -WD_API_Bot = HimoAPIBot(mr_or_bot="bot", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="bot", www="www") tax_translations_lower = {} -for tax_key, tax_lab in taxone_list.items(): # الأصنوفة +for tax_key, tax_lab in TAXONE_LIST.items(): # الأصنوفة if tax_lab.strip() and tax_key.strip(): - for natkey in sorted(tax_translations.keys()): # النوع - natar = tax_translations[natkey] + for natkey in sorted(TAX_TRANSLATIONS.keys()): # النوع + natar = TAX_TRANSLATIONS[natkey] if natkey.strip() and natar.strip(): kkey = tax_key.replace("~", natkey) tax_translations_lower[kkey.lower()] = tax_lab.replace("~", natar) @@ -34,12 +34,12 @@ def make_tax_des_new(item) -> str: return "" # --- P105 = Get_P_API_id(item, "P105") - P105ar = next((labforP105[p] for p in P105 if p in labforP105), "") + P105ar = next((LAB_FOR_P105[p] for p in P105 if p in LAB_FOR_P105), "") # --- if not P105ar: return "" # --- - tata = " ".join([f"wd:{x}" for x in lab_for_p171.keys()]) + tata = " ".join([f"wd:{x}" for x in LAB_FOR_P171.keys()]) # --- nan = f"""SELECT DISTINCT ?item ?P171 ?item105 WHERE {{ @@ -74,10 +74,10 @@ def make_tax_des_new(item) -> str: item105 = bs["item105"].split("/entity/")[1] P171 = bs["P171"].split("/entity/")[1] # --- - if P171 in lab_for_p171.keys(): - P171ar = lab_for_p171[P171] + if P171 in LAB_FOR_P171.keys(): + P171ar = LAB_FOR_P171[P171] ar_lab = f"{P105ar} {P171ar}" - WD_API_Bot.Des_API(q, ar_lab, "ar") + WdApiBot.des_api(q, ar_lab, "ar") def work_taxon_desc(item, endesc) -> None: @@ -90,4 +90,4 @@ def work_taxon_desc(item, endesc) -> None: print(f" no ardesc for en:{endesc}.") make_tax_des_new(item) - WD_API_Bot.Des_API(q, ardesc, "ar") + WdApiBot.des_api(q, ardesc, "ar") diff --git a/src/nep/new_way.py b/src/nep/new_way.py index 1b88eeb..b96a9d8 100644 --- a/src/nep/new_way.py +++ b/src/nep/new_way.py @@ -1,13 +1,6 @@ #!/usr/bin/python3 -""" +""" """ -from nep.new_way import P1433_ids, do_P1433_ids, P1433_en_to_qid -tfj run nldes3 --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py neq/nldes3 a2r sparql:Q13433827,Q265158,Q191067,Q19389637,Q953806 all:1000 doar" - -python3 core8/pwb.py neq/nldes3 a2r sparql:Q13442814 all:1000 doar -python3 core8/pwb.py neq/nldes3 a2r sparql:Q13433827,Q265158,Q191067,Q19389637,Q953806 all:1000 doar - -""" from nep.bots.its import its_a_generalthing P1433_ids = { diff --git a/src/nep/nldesc.py b/src/nep/nldesc.py index 473bacc..801aef9 100644 --- a/src/nep/nldesc.py +++ b/src/nep/nldesc.py @@ -5,8 +5,9 @@ import re import sys -from bots_subs.hi_api import HimoAPIBot -from bots_subs.wd_api import wd_bot +from shared.himo_api import HimoAPIBot +from wd_api import wd_bot + from des.railway import railway_tables, work_railway from desc_dicts.descraptions import Qid_Descraptions from nep.bots.helps import get_mainsnak @@ -30,7 +31,7 @@ from nep.tables.str_descs import make_nn from nep.wr_people import work_people -WD_API_Bot = HimoAPIBot(mr_or_bot="bot", www="www") +WdApiBot = HimoAPIBot(mr_or_bot="bot", www="www") logger = logging.getLogger(__name__) items2do = 0 # global parameter to print progress @@ -134,7 +135,7 @@ def action_one_P131_item(lng, oneitem) -> int: def Add_desc(q, value, lang) -> None: - WD_API_Bot.Des_API(q, value, lang, ask="") + WdApiBot.des_api(q, value, lang, ask="") def action_one_item(lngr, q, item=None, claimstr: str = ""): diff --git a/src/nep/others/read_json.py b/src/nep/others/read_json.py index 62f8985..1da1eac 100644 --- a/src/nep/others/read_json.py +++ b/src/nep/others/read_json.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 """ """ - import json import logging import re diff --git a/src/nep/si3.py b/src/nep/si3.py index b9d6a9d..73bfec4 100644 --- a/src/nep/si3.py +++ b/src/nep/si3.py @@ -1,15 +1,14 @@ #!/usr/bin/python3 -""" -from nep.si3 import do_P1433_new_list, work_new_list, make_scientific_art -""" +""" """ import logging import sys -from bots_subs.wd_api import wd_bot -from bots_subs.wd_api.wd_desc import work_api_desc +from wd_api import wd_bot +from wd_api.wd_desc import work_api_desc + from des.desc import work_one_item -from des.places import placesTable +from des.places import PLACES_TABLE from des.railway import railway_tables, work_railway from des.ru_st_2_latin import make_en_label from desc_dicts.descraptions_dict_new import get_data @@ -33,26 +32,26 @@ logger = logging.getLogger(__name__) -def work_a_desc(NewDesc, qid, fixlang) -> str: +def work_a_desc(new_desc_data, qid, fixlang) -> str: # --- if MainTestTable[1] or "dd" in sys.argv: logger.info("<> Without save:") - logger.info(NewDesc.keys()) - logger.info(NewDesc) + logger.info(new_desc_data.keys()) + logger.info(new_desc_data) return "" # --- - work_api_desc(NewDesc, qid, fixlang=fixlang) + work_api_desc(new_desc_data, qid, fixlang=fixlang) -def make_scientific_art(item, P31, num: int) -> None: +def make_scientific_art(item, p31, num: int) -> None: # --- - table = make_scientific_article(item, P31, num, TestTable=MainTestTable[1]) + table = make_scientific_article(item, p31, num, testtable=MainTestTable[1]) # --- - NewDesc = table["descriptions"] + new_desc_data = table["descriptions"] qid = table["qid"] rep_langs = table["fixlang"] # --- - work_a_desc(NewDesc, qid, rep_langs) + work_a_desc(new_desc_data, qid, rep_langs) def do_P1433_new_list(item, p31) -> None: @@ -60,16 +59,16 @@ def do_P1433_new_list(item, p31) -> None: logger.info(" do_P1433_new_list: ") # --- q = item["q"] - NewDesc = {} + new_desc_data = {} # --- orig_desc = item.get("descriptions", {}).get("ar", "") # --- ar_desc = do_P1433_ids(item, p31, orig_desc) # --- if ar_desc: - NewDesc["ar"] = {"language": "ar", "value": ar_desc} + new_desc_data["ar"] = {"language": "ar", "value": ar_desc} logger.info(f"<> ** do_P1433_new_list p31:{p31}") - work_a_desc(NewDesc, q, []) + work_a_desc(new_desc_data, q, []) else: print("do_P1433_new_list nothing to add. ") @@ -79,15 +78,15 @@ def work_new_list(item, p31, ardes) -> None: logger.info(f" work_new_list: {ardes=}") # --- q = item["q"] - NewDesc = {} + new_desc_data = {} # --- - gg = Qids_translate.get(p31) or others_list.get(p31) or placesTable.get(p31) or {} + gg = Qids_translate.get(p31) or others_list.get(p31) or PLACES_TABLE.get(p31) or {} ggx = {} # --- for lang in ggx.keys(): if lang not in item.get("descriptions", {}).keys(): if gg[lang]: - NewDesc[lang] = {"language": lang, "value": gg[lang]} + new_desc_data[lang] = {"language": lang, "value": gg[lang]} # --- orig_desc = item.get("descriptions", {}).get("ar", "") en_desc = item.get("descriptions", {}).get("en", "") @@ -109,12 +108,12 @@ def work_new_list(item, p31, ardes) -> None: # --- # if ar_desc and ardes != ar_desc : if ar_desc: - NewDesc["ar"] = {"language": "ar", "value": ar_desc} + new_desc_data["ar"] = {"language": "ar", "value": ar_desc} # --- - # logger.info( '<> NewDesc' + str(NewDesc) ) - if NewDesc != {}: + # logger.info( '<> new_desc_data' + str(new_desc_data) ) + if new_desc_data != {}: logger.info(f"<> ** work_new_list p31:{p31}") - work_a_desc(NewDesc, q, []) + work_a_desc(new_desc_data, q, []) else: print("work_new_list nothing to add. ") @@ -123,7 +122,7 @@ def work_qid_desc(item, topic, num: int) -> None: logger.info("<> work_qid_desc: ") q = item["q"] descriptions = item.get("descriptions", {}) - NewDesc = {} + new_desc_data = {} addedlangs = [] # --- replace_descraptions = get_data("replace_descraptions") @@ -134,25 +133,25 @@ def work_qid_desc(item, topic, num: int) -> None: # --- if lang not in descriptions.keys(): # descriptions[lang] = Qids_translate[topic][lang] - NewDesc[lang] = {"language": lang, "value": Qids_translate[topic][lang]} + new_desc_data[lang] = {"language": lang, "value": Qids_translate[topic][lang]} addedlangs.append(lang) elif descriptions[lang] in des_for_lang: orgdisc = descriptions[lang] - NewDesc[lang] = {"language": lang, "value": des_for_lang[orgdisc]} + new_desc_data[lang] = {"language": lang, "value": des_for_lang[orgdisc]} # --- - if not NewDesc: + if not new_desc_data: print("work_qid_desc nothing to add. ") return # --- - if len(NewDesc) < 5: - logger.info(f"<> len of NewDesc < 5: ({str(NewDesc)})") + if len(new_desc_data) < 5: + logger.info(f"<> len of new_desc_data < 5: ({str(new_desc_data)})") return # --- logger.info(f"<> **{num}: work_qid_desc:{q} ({topic})") - work_a_desc(NewDesc, q, []) + work_a_desc(new_desc_data, q, []) -def ISRE(qitem, num: int, lenth, no_donelist: bool = True, P31_list: bool = False, get_nl_des: bool = True): +def ISRE(qitem, num: int, lenth, no_donelist: bool = True, p31_list: bool = False, get_nl_des: bool = True): # --- logger.info(f"--- *<> >{num}/{lenth}: q:{qitem}") # --- @@ -175,12 +174,12 @@ def ISRE(qitem, num: int, lenth, no_donelist: bool = True, P31_list: bool = Fals labels = item.get("labels", {}) if labels.get("en", "") == "": logger.info("item enlabel == ''") - make_en_label(labels, q, Add=Add_en_labels[1]) + make_en_label(labels, q, add_it=Add_en_labels[1]) # --- P31_table = [] # --- - if P31_list and P31_list != [] and isinstance(P31_list, list): - P31_table = P31_list + if p31_list and p31_list != [] and isinstance(p31_list, list): + P31_table = p31_list else: P31_table = Get_P_API_id(item, "P31") # --- @@ -223,9 +222,9 @@ def ISRE(qitem, num: int, lenth, no_donelist: bool = True, P31_list: bool = Fals work_new_list(item, P31, ardes) break # --- - elif P31 in Geo_List and placesTable.get(P31, {}).get("ar"): + elif P31 in Geo_List and PLACES_TABLE.get(P31, {}).get("ar"): work_one_item( - placesTable.get(P31, {}).get("ar"), + PLACES_TABLE.get(P31, {}).get("ar"), "ar", {"q": item["q"]}, 0, diff --git a/src/nep/si3g.py b/src/nep/si3g.py index e932058..1060162 100644 --- a/src/nep/si3g.py +++ b/src/nep/si3g.py @@ -1,52 +1,6 @@ #!/usr/bin/python3 """ -tfj run new1 --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py nep/si3g -family:wikidata -lang:wikidata -start:Q500" - -tfj run ghu --mem 1Gi --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py nep/si3g -newpages:40000" -tfj run ghu --mem 1Gi --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py nep/si3g -usercontribs:Ghuron" -tfj run Q482994 --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py neq/nldes3 a2r sparql:Q482994" - إضافة وصف لعناصر ويكي بيانات الجديدة - -python3 core8/pwb.py nep/si3g -ns:0 -offset:5000 -newpages:10000 - -python3 core8/pwb.py nep/si3g -newpages:200 -python3 core8/pwb.py nep/si3g -newpages:100 ask - -python3 core8/pwb.py nep/si3g ask -page:Q21205603 -python3 core8/pwb.py nep/si3g ask -page:Q130316095 -python3 core8/pwb.py nep/si3g ask -page:Q130340916 -python3 core8/pwb.py nep/si3g ask -page:Q21032508 -python3 core8/pwb.py nep/si3g -page: -python3 core8/pwb.py nep/si3g -page: -python3 core8/pwb.py nep/si3g -page:Q301263 -python3 core8/pwb.py nep/si3g -page: -python3 core8/pwb.py nep/si3g -page: -python3 core8/pwb.py nep/si3g -page:Q131442910 -python3 core8/pwb.py nep/si3g -page:Q130212038 -python3 core8/pwb.py nep/si3g -page:Q129594209 -python3 core8/pwb.py nep/si3g -page:Q112167358 -python3 core8/pwb.py nep/si3g -page:Q122652815 -python3 core8/pwb.py nep/si3g -page:Q113510544 -python3 core8/pwb.py nep/si3g -page:Q111771063 -python3 core8/pwb.py nep/si3g -start:Q98512481 -python3 core8/pwb.py nep/si3g -start:Q97950000 -python3 core8/pwb.py nep/si3g -start:Q97949000 -python3 core8/pwb.py nep/si3g -start:Q111771064 err - -python3 core8/pwb.py nep/si3g -newpages:200 - -python pwb.py nep/si3g -newpages:200 -python3 core8/pwb.py nep/si3g -newpages:200 ask - -# python3 core8/pwb.py nep/si3g -newpages:50 -# python3 core8/pwb.py nep/si3g -newpages:500 -# python pwb.py nep/si3g -newpages:100 -# python3 core8/pwb.py nep/si3g -limit:3000 -ns:0 -usercontribs:Research_Bot -# python3 core8/pwb.py nep/si3g -limit:6000 -ns:0 -usercontribs:Succu -# python3 core8/pwb.py nep/si3g -limit:6000 -ns:0 -usercontribs:LargeDatasetBot -# python3 core8/pwb.py nep/si3g -limit:6000 -ns:0 -usercontribs:Research_Bot - """ import logging @@ -54,11 +8,11 @@ import time from pathlib import Path -import wd_gent -from nep import si3 - from shared.api_page import load_main_api +from nep import si3 +from wd_core import wd_gent + logger = logging.getLogger(__name__) sys.argv.append("-family:wikidata") @@ -72,9 +26,6 @@ def mainwithcat2() -> None: logger.info("*<> > mainwithcat2:") # --- - # python3 core8/pwb.py nep/si3g -newpages:10 - # python3 core8/pwb.py nep/si3g -newpages:1000 - # python3 core8/pwb.py nep/si3g -newpages:20000 # --- start = time.time() # --- @@ -98,27 +49,15 @@ def mainwithcat2() -> None: elif arg == "-newpages": newpages = value # --- - # python3 core8/pwb.py nep/si3g -file:dump/artest/Q7187.txt - # python3 core8/pwb.py nep/si3g -file:dump/artest/Q1457376.txt if arg == "-file": file = value # --- - # python3 core8/pwb.py nep/si3g -artest:Q523 - # python3 core8/pwb.py nep/si3g -artest:Q318 - # python3 core8/pwb.py nep/si3g -artest:Q13442814 - # python3 core8/pwb.py nep/si3g -artest:Q21672098 - # python3 core8/pwb.py nep/si3g -artest:Q1516079 - # python3 core8/pwb.py nep/si3g -artest:Q427087 - # python3 core8/pwb.py nep/si3g -artest:Q79007 - # python3 core8/pwb.py nep/si3g -artest:Q7187 if arg == "-artest": file = f"dump/artest/{value}.txt" # --- if arg == "-page": lista.append(value) # --- - # python3 core8/pwb.py nep/si3g -ns:0 -usercontribs:Edoderoobot - # python3 core8/pwb.py nep/si3g -ns:0 -usercontribs:Ghuron if arg in ["-user", "-usercontribs"]: user = value # --- diff --git a/src/nep/si3g_qua.py b/src/nep/si3g_qua.py index 54935a8..b62727d 100644 --- a/src/nep/si3g_qua.py +++ b/src/nep/si3g_qua.py @@ -1,21 +1,13 @@ #!/usr/bin/python3 -""" -tfj run egy --image python3.9 --command "$HOME/local/bin/python3 core8/pwb.py nep/si3g_qua returnlab -p27:Q79" +""" """ -python3 core8/pwb.py nep/si3g_qua returnlab -lang:ar - -python3 core8/pwb.py nep/si3g_qua returnlab - -python3 core8/pwb.py nep/si3g_qua returnlab -p27:Q1028 -python3 core8/pwb.py nep/si3g_qua returnlab -p27:Q79 - -""" import logging import random import sys import time -from bots_subs.wd_api import wd_bot, wd_sparql_bot +from wd_api import wd_bot, wd_sparql_bot + from nep.wr_people import work_people from people.people_get_topic import print_new_jobs, qid_to_job, qid_to_p27 diff --git a/src/nep/space_others.py b/src/nep/space_others.py index 8dddea2..720117a 100644 --- a/src/nep/space_others.py +++ b/src/nep/space_others.py @@ -1,7 +1,5 @@ #!/usr/bin/python3 -""" -from nep.space_others import Make_space_desc, Make_others_desc -""" +""" """ import logging import re @@ -19,7 +17,7 @@ ) from nep.new_way import P1433_ids, do_P1433_ids from nep.tables.lists import ( - Geo_entity, + GEO_ENTITY, Space_tab, bldiat, others_list, @@ -156,8 +154,8 @@ def Make_others_desc(lng, wditem, type_of_item, orig_desc, claimstr: str = ""): if orig_desc in ["شارع", ""]: my_description = its_something_in_an_entity(wditem, "شارع في") # --- - elif type_of_item in Geo_entity: - labr = Geo_entity[type_of_item] + elif type_of_item in GEO_ENTITY: + labr = GEO_ENTITY[type_of_item] if orig_desc in [labr, ""]: my_description = its_something_in_an_entity(wditem, f"{labr} في") # --- diff --git a/src/nep/tables/lists.py b/src/nep/tables/lists.py index 5024188..afc61d0 100644 --- a/src/nep/tables/lists.py +++ b/src/nep/tables/lists.py @@ -2,7 +2,7 @@ This module defines mappings and SPARQL queries for various entities. It is used for [describe the purpose] in the context of [describe the context]. -from nep.tables.lists import p50s, space_list_and_other, Taton_list, Space_tab, others_list_2, others_list, Geo_entity, bldiat, qura, songs_type, space_list_and_other_2, Taton_list +from nep.tables.lists import p50s, space_list_and_other, Taton_list, Space_tab, others_list_2, others_list, GEO_ENTITY, bldiat, qura, songs_type, space_list_and_other_2, Taton_list in si3.py : from nep.tables.lists import space_list_and_other, others_list, Space_tab, others_list_2 @@ -101,7 +101,7 @@ "Q207628", # compositie ] -simple_set_byP131 = [ +simple_set_byp131 = [ "Q24764", "Q70208", "Q127448", @@ -172,7 +172,7 @@ "", ] -Geo_entity = { +GEO_ENTITY = { "Q4989906": "معلم تذكاري", "Q13424466": "ميناء طبيعي", "Q30022": "مقهى", @@ -301,8 +301,8 @@ # 'Q11424':{"ar":"فيلم", "en":"" }, } -for geo in Geo_entity: - others_list[geo] = {"ar": Geo_entity[geo], "en": ""} +for geo in GEO_ENTITY: + others_list[geo] = {"ar": GEO_ENTITY[geo], "en": ""} bldiat = { "Q484170": "فرنسا", # a 37477 @@ -326,7 +326,7 @@ } for vv in bldiat: - others_list[vv] = {"ar": f"بلدية في {bldiat[vv]}" ""} + others_list[vv] = {"ar": f"بلدية في {bldiat[vv]}"} qura = { "Q21672098": {"P17": "أوكرانيا", "P31": "قرية"}, diff --git a/src/nep/tables/nats.py b/src/nep/tables/nats.py index a7338df..e1d9155 100644 --- a/src/nep/tables/nats.py +++ b/src/nep/tables/nats.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -""" -from nep.tables.nats import nationalities -""" +""" """ nationalities = { "آيسلندا": {"man": "آيسلندي", "women": "آيسلندية"}, diff --git a/src/nep/tables/si_tables.py b/src/nep/tables/si_tables.py index f770335..4510079 100644 --- a/src/nep/tables/si_tables.py +++ b/src/nep/tables/si_tables.py @@ -1,10 +1,8 @@ -""" -from nep.tables.si_tables import genders, MainTestTable, new_types, offsetbg, Qids_translate, Add_en_labels, Geo_List -""" +""" """ import sys -from des.places import placesTable +from des.places import PLACES_TABLE from desc_dicts.descraptions import DescraptionsTable, Qid_Descraptions from desc_dicts.descraptions_dict import Scientific_descraptions from nep.tables.lists import others_list @@ -74,4 +72,4 @@ Add_en_labels[1] = "addenlabel" in sys.argv -Geo_List = list(placesTable.keys()) +Geo_List = list(PLACES_TABLE.keys()) diff --git a/src/nep/tables/str_descs.py b/src/nep/tables/str_descs.py index daa9aad..b6144a8 100644 --- a/src/nep/tables/str_descs.py +++ b/src/nep/tables/str_descs.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 -""" -from nep.tables.str_descs import descs, entities, countries, genese, make_nn -""" +""" """ + +from wd_api import wd_bot -from bots_subs.wd_api import wd_bot from nep.bots.helps import ( Get_label_from_item, get_label_txt, diff --git a/src/nep/wr_people.py b/src/nep/wr_people.py index 9adcc83..7469874 100644 --- a/src/nep/wr_people.py +++ b/src/nep/wr_people.py @@ -8,7 +8,8 @@ import logging import re -from bots_subs.wd_api.wd_desc import work_api_desc +from wd_api.wd_desc import work_api_desc + from nep.tables.lists import en_des_to_ar from nep.tables.si_tables import genders from people.new3 import translations_o @@ -58,7 +59,7 @@ def work_people2(item, topic, num: int = 0, years: str = ""): # --- descriptions = item.get("descriptions", {}) # --- - NewDesc = {} + new_desc_data = {} # --- p21_c = genders.get(p21) # --- @@ -69,18 +70,18 @@ def work_people2(item, topic, num: int = 0, years: str = ""): for lang, lang_tab in taber.items(): # --- if lang_tab.get(p21_c) and lang not in descriptions.keys(): - NewDesc[lang] = {"language": lang, "value": lang_tab.get(p21_c)} + new_desc_data[lang] = {"language": lang, "value": lang_tab.get(p21_c)} # --- if years and lang in ["en", "ar", "en-ca", "en-gb"]: - NewDesc[lang]["value"] += years + new_desc_data[lang]["value"] += years # --- - if not NewDesc: + if not new_desc_data: print(" work_people nothing to add. ") return None # --- logger.info(f"<> **{num}: work_people:{q} ({topic})") # --- - work_api_desc(NewDesc, q, fixlang=[]) + work_api_desc(new_desc_data, q, fixlang=[]) def work_people(item, topic, num: int, ardes): diff --git a/src/neq/nldes3.py b/src/neq/nldes3.py index ba8af5e..4c8614c 100644 --- a/src/neq/nldes3.py +++ b/src/neq/nldes3.py @@ -1,22 +1,13 @@ #!/usr/bin/python3 -""" -python3 core8/pwb.py neq/nldes3 a2r sparql:Q13433827,Q265158,Q191067,Q19389637,Q953806 all:1000 doar +""" """ -python3 core8/pwb.py neq/nldes3 a2r sparql:Q953806 ask all:100 doar - -python3 core8/pwb.py neq/nldes3 test - -python3 core8/pwb.py neq/nldes3 a2r sparql:dfd ask -python3 core8/pwb.py neq/nldes3 a2r sparql:Q7889 ask -python3 core8/pwb.py neq/nldes3 a2r sparql:Q7889 ask - -""" import logging import random import re import sys -from bots_subs.wd_api.wd_sparql_bot import sparql_generator_big_results +from wd_api.wd_sparql_bot import sparql_generator_big_results + from nep.nldesc import action_one_item from neq.quarries import SPARQLSE diff --git a/src/neq/quarries.py b/src/neq/quarries.py index f624417..acad0a7 100644 --- a/src/neq/quarries.py +++ b/src/neq/quarries.py @@ -5,10 +5,10 @@ """ - import sys from desc_dicts.descraptions import Qid_Descraptions +from nep.new_way import P1433_ids from nep.tables.lists import ( Space_tab, Taton_list, @@ -72,8 +72,9 @@ def do_qua(qid, prop: str = "", ad: str = "", ar_values: str = ""): for p50 in p50s: SPARQLSE[f"{p50}dfd"] = do_qua(p50, prop="wdt:P50") - SPARQLSE[p50] = ( - f""" + SPARQLSE[ + p50 + ] = f""" SELECT DISTINCT ?item (GROUP_CONCAT(DISTINCT(STR(?labe)); separator="@@") as ?lab) @@ -84,7 +85,6 @@ def do_qua(qid, prop: str = "", ad: str = "", ar_values: str = ""): FILTER(NOT EXISTS {{?item schema:description ?des.FILTER((LANG(?des)) = "ar")}}) }} GROUP BY ?item """ - ) # رواية @@ -266,9 +266,6 @@ def do_qua(qid, prop: str = "", ad: str = "", ar_values: str = ""): # أغنية SPARQLSE["Q7366"] = do_qua("Q7366", prop="wdt:P175", ad="") - -from nep.new_way import P1433_ids - for qid, va in P1433_ids.items(): prop = "|".join([f"wdt:{p['p']}" for p in va["props"]]) prop = f"({prop})" @@ -282,7 +279,6 @@ def do_qua(qid, prop: str = "", ad: str = "", ar_values: str = ""): qua = do_qua(qid, prop=prop, ad="", ar_values=ar_values.strip()) SPARQLSE[qid] = qua # --- - # if "doar" in sys.argv: print(f"python3 core8/pwb.py neq/nldes3 a2r sparql:{qid} all:1000 doar") SPARQLSE[ "Q13442814" diff --git a/src/people/Nationalities.py b/src/people/Nationalities.py index 4f8db01..b8b0bcc 100644 --- a/src/people/Nationalities.py +++ b/src/people/Nationalities.py @@ -10,22 +10,16 @@ """ + import json from pathlib import Path Dir = Path(__file__).parent -translationsNationalities = {} +TRANSLATIONS_NATIONALITIES = {} with open(f"{Dir}/translationsNationalities.json", "r", encoding="utf-8") as f: - translationsNationalities = json.load(f) - -translationsNationalities["Luxembourgian"] = translationsNationalities["Luxembourg"] -translationsNationalities["New Zealander"] = translationsNationalities["New Zealand"] - -tra = translationsNationalities + TRANSLATIONS_NATIONALITIES = json.load(f) -if __name__ == "__main__": - # python3 core8/pwb.py people/Nationalities - for k in tra.keys(): - print(f'\t"{k}" : "",') +TRANSLATIONS_NATIONALITIES["Luxembourgian"] = TRANSLATIONS_NATIONALITIES["Luxembourg"] +TRANSLATIONS_NATIONALITIES["New Zealander"] = TRANSLATIONS_NATIONALITIES["New Zealand"] diff --git a/src/people/new3.py b/src/people/new3.py index 2494528..b40d37c 100644 --- a/src/people/new3.py +++ b/src/people/new3.py @@ -1,10 +1,6 @@ #!/usr/bin/python3 """ -python3 core8/pwb.py people/new3 -python3 core8/pwb.py people/new3 -job:rules_footballer ask -python3 core8/pwb.py people/new3 -nat:Yemeni ask -python3 core8/pwb.py people/new3 -nat:American limit:200 SELECT * WHERE { @@ -40,10 +36,11 @@ import sys import time -import people.occupationsall as oc -from bots_subs.wd_api import wd_sparql_bot -from bots_subs.wd_api.wd_desc import work_api_desc -from people.Nationalities import translationsNationalities +from wd_api import wd_sparql_bot +from wd_api.wd_desc import work_api_desc + +from people import occupationsall as oc +from people.Nationalities import TRANSLATIONS_NATIONALITIES logger = logging.getLogger(__name__) @@ -60,23 +57,18 @@ Tab = { - "Nationalities": translationsNationalities, - "Occupations": oc.translationsOccupations, + "Nationalities": TRANSLATIONS_NATIONALITIES, + "Occupations": oc.TRANSLATIONS_OCCUPATIONS, } -logger.info(f"len of Nationalities = {len(translationsNationalities.keys())}") -logger.info(f"len of Occupations = {len(oc.translationsOccupations.keys())}") +logger.info(f"len of Nationalities = {len(TRANSLATIONS_NATIONALITIES.keys())}") +logger.info(f"len of Occupations = {len(oc.TRANSLATIONS_OCCUPATIONS.keys())}") time.sleep(1) qualimit = {1: 20} limit = {1: ""} offset = {1: 0} -# python3 core8/pwb.py people/new3 occnew -# python3 core8/pwb.py people/new3 -job:researcher -# python3 core8/pwb.py people/new3 -nat:Yemeni -job:footballer -# python3 core8/pwb.py people/new3 -nat:American occnew -# python3 core8/pwb.py people/new3 -nat:American for arg in sys.argv: # --- arg, _, value = arg.partition(":") @@ -91,21 +83,21 @@ offset[1] = int(value) # --- if arg == "occnew": - Tab["Occupations"] = oc.translationsOccupations_new + Tab["Occupations"] = oc.TRANSLATIONS_OCCUPATIONS_NEW # --- if arg in ["nat", "-nat"]: value = value.replace("_", " ") - if value in translationsNationalities: - Tab["Nationalities"] = {value: translationsNationalities[value]} + if value in TRANSLATIONS_NATIONALITIES: + Tab["Nationalities"] = {value: TRANSLATIONS_NATIONALITIES[value]} else: - print(f"nat value:({value}) not in translationsNationalities") + print(f"nat value:({value}) not in TRANSLATIONS_NATIONALITIES") # --- if arg in ["job", "-job"]: value = "~ " + value.replace("_", " ") - if value in oc.translationsOccupations: - Tab["Occupations"] = {value: oc.translationsOccupations[value]} + if value in oc.TRANSLATIONS_OCCUPATIONS: + Tab["Occupations"] = {value: oc.TRANSLATIONS_OCCUPATIONS[value]} else: - print(f"job value:({value}) not in oc.translationsOccupations") + print(f"job value:({value}) not in oc.TRANSLATIONS_OCCUPATIONS") targetlangs2 = ["ar"] targetlangs = ["ar", "bn", "ca", "es", "fr", "gl", "he"] @@ -139,8 +131,6 @@ def check_quarry_new(tab): if d not in tabe: tabe[d] = [] # --- - # python3 core8/pwb.py people/new3 -nat:Algerian limit:500 qualimit:15 - # python3 core8/pwb.py people/new3 -nat:American limit:50 qualimit:10 if len(tabe[d]) < qualimit[1]: tabe[d].append(x) else: @@ -194,7 +184,7 @@ def check_quarry_new(tab): def make_Tabs(tabs) -> None: # من هذا البوت - # TraOc = translationsOccupations + # TraOc = TRANSLATIONS_OCCUPATIONS TraNat = tabs["Nationalities"] # --- # من البوتات الأخرى @@ -327,25 +317,25 @@ def start_one_nat(nat_tab) -> None: genderlabel = genders.get(p21, "male") # --- descriptions_keys = sorted(x["deskey"].split(",")) - NewDesc = { + new_desc_data = { lang: {"language": lang, "value": x_table[lang][genderlabel]} for lang in x_table.keys() if lang not in descriptions_keys } # --- - if NewDesc != {}: - work_api_desc(NewDesc, q) + if new_desc_data != {}: + work_api_desc(new_desc_data, q) -def mainnat(Tabs) -> None: # translations_for_nat +def mainnat(tabs) -> None: # translations_for_nat # --- # python pwb.py people/new3 mainnat -nat:American # # --- logger.info("<>------------\n mainnat :") # --- - if Tabs != {}: - make_Tabs(Tabs) + if tabs != {}: + make_Tabs(tabs) # --- Queries = 0 # --- diff --git a/src/people/occupationsall.py b/src/people/occupationsall.py index a86e4ea..2a9f343 100644 --- a/src/people/occupationsall.py +++ b/src/people/occupationsall.py @@ -20,7 +20,7 @@ Dir = Path(__file__).parent -translationsOccupations = {} +TRANSLATIONS_OCCUPATIONS = {} tra_occ_2 = { "~ critic": { "ar": {"male": "ناقد ~", "female": "ناقدة ~"}, @@ -130,11 +130,11 @@ } with open(f"{Dir}/translationsOccupations.json", "r", encoding="utf-8") as f: - translationsOccupations = json.load(f) + TRANSLATIONS_OCCUPATIONS = json.load(f) -translationsOccupations.update(tra_occ_2) +TRANSLATIONS_OCCUPATIONS.update(tra_occ_2) -translationsOccupations_new = { +TRANSLATIONS_OCCUPATIONS_NEW = { "~ Indigenous artist": { "ar": {"male": "فنان سكان أصليون ~", "female": "فنانة سكان أصليون ~"}, "en": {"male": "~ Indigenous artist", "female": "~ Indigenous artist"}, @@ -618,17 +618,13 @@ }, } -translations_all = {**translationsOccupations, **translationsOccupations} +translations_all = {**TRANSLATIONS_OCCUPATIONS, **TRANSLATIONS_OCCUPATIONS} -# for x in translationsOccupations: -# if "ar" not in translationsOccupations[x]: -# print( x ) - -for x, yy in translationsOccupations_new.items(): +for x, yy in TRANSLATIONS_OCCUPATIONS_NEW.items(): if "ar" in yy: - translationsOccupations[x] = yy + TRANSLATIONS_OCCUPATIONS[x] = yy translations_all[x] = yy -for yy in translationsOccupations.values(): +for yy in TRANSLATIONS_OCCUPATIONS.values(): if "ar" in yy and yy["ar"]["male"] == yy["ar"]["female"]: print(f" male:{yy['ar']['male']} == female") diff --git a/src/people/people_get_topic.py b/src/people/people_get_topic.py index a38c9c7..83f5c9c 100644 --- a/src/people/people_get_topic.py +++ b/src/people/people_get_topic.py @@ -5,7 +5,6 @@ from people.people_get_topic import get_topic from people.people_get_topic import print_new_jobs -python3 core8/pwb.py people/people_get_topic SELECT ?item ?dem WHERE { ?item wdt:P31 wd:Q3624078; @@ -14,6 +13,7 @@ } """ + import logging import sys diff --git a/src/prop_labs/fill_ar_props.py b/src/prop_labs/fill_ar_props.py index a661459..d1565f1 100644 --- a/src/prop_labs/fill_ar_props.py +++ b/src/prop_labs/fill_ar_props.py @@ -33,9 +33,10 @@ from SPARQLWrapper import JSON, SPARQLWrapper from tqdm import tqdm from translate_bot import translate_en_to_ar -from wd_core_useraccount import User_tables_ibrahem from wd_Session import WikidataSession +from wd_core_useraccount import User_tables_ibrahem + logger = logging.getLogger(__name__) WDQS_ENDPOINT = "https://query.wikidata.org/sparql" diff --git a/src/prop_labs/wd_Session.py b/src/prop_labs/wd_Session.py index 79e0da1..8ea968d 100644 --- a/src/prop_labs/wd_Session.py +++ b/src/prop_labs/wd_Session.py @@ -8,6 +8,7 @@ from typing import Dict, List import requests + from wd_core_useraccount import User_tables_ibrahem logger = logging.getLogger(__name__) diff --git a/src/wd_gent.py b/src/wd_gent.py index 84bf5d8..73dd5f8 100644 --- a/src/wd_gent.py +++ b/src/wd_gent.py @@ -1,12 +1,12 @@ #!/usr/bin/python3 """ """ + import logging import sys from typing import Iterable import pywikibot from pywikibot import pagegenerators - from shared.api_page import load_main_api logger = logging.getLogger(__name__) @@ -20,7 +20,6 @@ def fetch_user_new_pages(limit: int = "max", namespace: str = "0", user: str = " def getusernewpages(): - # python3 core8/pwb.py wd_gent -mynewpages:10 -ns:0 usernewpages = "" ns = "" limit = 100