From a42a64a3308c272b7b9ace19f396eab38133070b Mon Sep 17 00:00:00 2001 From: ibrahem Date: Thu, 28 Mar 2024 03:22:28 +0300 Subject: [PATCH 1/5] Update wrk_pages.py --- ncc_core/nc_import/bots/wrk_pages.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ncc_core/nc_import/bots/wrk_pages.py b/ncc_core/nc_import/bots/wrk_pages.py index 90825c11..79892eab 100644 --- a/ncc_core/nc_import/bots/wrk_pages.py +++ b/ncc_core/nc_import/bots/wrk_pages.py @@ -28,6 +28,12 @@ def start(self): # --- self.get_temps() self.work_on_temps() + # --- + if self.new_text == self.text: + printe.output("no changes") + return + # --- + self.add_category() self.save() def get_temps(self): @@ -79,9 +85,14 @@ def work_on_temps(self): if temp_new_text != string: self.new_text = self.new_text.replace(string, temp_new_text) + def add_category(self): + cat = "Category:Contains images from NC Commons" + # --- + if self.new_text.find(cat) == -1: + self.new_text += "\n[[Category:Contains images from NC Commons]]" + def save(self): - if self.new_text != self.text: - self.page.save(newtext=self.new_text, summary="bot: fix NC") + self.page.save(newtext=self.new_text, summary="bot: fix NC") def work_on_pages(code, pages): From d85f7d5446ef1afbbbad33bc7a5de5a0adbdf62c Mon Sep 17 00:00:00 2001 From: ibrahem Date: Thu, 28 Mar 2024 03:34:45 +0300 Subject: [PATCH 2/5] Update get_langs.py --- ncc_core/nc_import/bots/get_langs.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ncc_core/nc_import/bots/get_langs.py b/ncc_core/nc_import/bots/get_langs.py index 87f0f9ff..0c3ce37c 100644 --- a/ncc_core/nc_import/bots/get_langs.py +++ b/ncc_core/nc_import/bots/get_langs.py @@ -4,6 +4,7 @@ """ import re +import wikitextparser as wtp from newapi.ncc_page import MainPage as ncc_MainPage from newapi import printe @@ -26,9 +27,30 @@ def get_langs_codes(): """ text = get_text() langs = [] - fi = re.findall(r"\* (.*)\n", text) - for i in fi: - langs.append(i.strip()) + # * {{User:Mr. Ibrahem/import bot/line|ar}} + # --- + tmp = "User:Mr. Ibrahem/import bot/line" + # --- + prased = wtp.parse(text) + temps = prased.templates + for temp in temps: + # --- + name = str(temp.normal_name()).strip().lower().replace("_", " ") + # --- + printe.output(f"{temp.name=}, {name=}") + # --- + if name == tmp.lower(): + # --- + # get first argument + # --- + va = temp.get_arg("1") + if va and va.value: + langs.append(va.value.strip()) # --- printe.output(f"langs: {langs}") + # --- return langs + +if __name__ == "__main__": + # python3 core8/pwb.py nc_import/bots/get_langs + get_langs_codes() From 5092bdf58ee3073d3028da1ed2d40ebfb5f852c6 Mon Sep 17 00:00:00 2001 From: ibrahem Date: Thu, 28 Mar 2024 03:40:20 +0300 Subject: [PATCH 3/5] Update import_files.py --- ncc_core/nc_import/bots/import_files.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ncc_core/nc_import/bots/import_files.py b/ncc_core/nc_import/bots/import_files.py index 6857487a..8f49159c 100644 --- a/ncc_core/nc_import/bots/import_files.py +++ b/ncc_core/nc_import/bots/import_files.py @@ -3,6 +3,7 @@ bot for importing files from nccommons to wikipedia """ +import re import sys from newapi.ncc_page import MainPage as ncc_MainPage, NEW_API as ncc_NEW_API from newapi import printe @@ -22,6 +23,16 @@ def get_file_text(title): return text +def categories_work(text): + """ + remove all categories from the text + """ + # --- + text = re.sub(r"\[\[Category:(.*?)\]\]", "", text, flags=re.DOTALL) + # --- + text += "\n[[Category:Files imported from NC Commons]]" + # --- + return text def import_file(title, code): """ @@ -31,6 +42,8 @@ def import_file(title, code): # --- file_text = get_file_text(title) # --- + file_text = categories_work(file_text) + # --- api_new = ncc_NEW_API("www", family="nccommons") # api_new.Login_to_wiki() img_url = api_new.Get_image_url(title) From 2b5cf523b4373b5cc45ec70df01d838412cd076e Mon Sep 17 00:00:00 2001 From: ibrahem Date: Sat, 30 Mar 2024 05:49:46 +0300 Subject: [PATCH 4/5] Create views.py --- ncc_core/nc_import/views.py | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ncc_core/nc_import/views.py diff --git a/ncc_core/nc_import/views.py b/ncc_core/nc_import/views.py new file mode 100644 index 00000000..7cc4378e --- /dev/null +++ b/ncc_core/nc_import/views.py @@ -0,0 +1,52 @@ +""" + +python3 core8/pwb.py nc_import/views +fetch("https://pageviews.wmcloud.org/pageviews/api.php?pages=Kat%7CHond&project=af.wikipedia.org&start=2015-07-01&end=2024-03-27&totals=true", { + "headers": { + "accept": "*/*", + "accept-language": "ar-EG,ar;q=0.9,en-US;q=0.8,en;q=0.7,sk;q=0.6,zh-CN;q=0.5,zh-TW;q=0.4,zh;q=0.3", + "sec-ch-ua": "\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\"Windows\"", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "x-requested-with": "XMLHttpRequest" + }, + "referrer": "https://pageviews.wmcloud.org/pageviews/?project=af.wikipedia.org&platform=all-access&agent=user&redirects=0&range=all-time&pages=Kat|Hond", + "referrerPolicy": "strict-origin-when-cross-origin", + "body": null, + "method": "GET", + "mode": "cors", + "credentials": "omit" +}); +""" +from nc_import.bots.get_langs import get_langs_codes + +def get_views(code): + endpoint = "https://pageviews.wmcloud.org/massviews/api.php" + category = "Category:Files_imported_from_NC_Commons" + # --- + # https://pageviews.wmcloud.org/massviews/api.php?project=af.wikipedia.org&category=Files_imported_from_NC_Commons&limit=20000 + # --- + params = { + "project": f"{code}.wikipedia.org", + "category": category + } + # --- + # result example: [{"title":"Chondrosarcoma_of_the_nasal_septum_(Radiopaedia_165701-135935_Sagittal_2).jpeg","ns":6}] + # --- + + +def start(): + """ + A function that starts the process by iterating over languages, getting pages for each language, and then working on those pages. + """ + langs = get_langs_codes() + # --- + for code in langs: + pages = get_views(code) + + +if __name__ == "__main__": + start() From aaf478367ccff92e7a2867b6f151358ab6e70c02 Mon Sep 17 00:00:00 2001 From: ibrahem Date: Tue, 2 Apr 2024 00:37:14 +0300 Subject: [PATCH 5/5] . --- .github/workflows/{update_md.yml => update_pybot.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{update_md.yml => update_pybot.yml} (100%) diff --git a/.github/workflows/update_md.yml b/.github/workflows/update_pybot.yml similarity index 100% rename from .github/workflows/update_md.yml rename to .github/workflows/update_pybot.yml