diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/newapi/DB_bots/db_bot.py b/newapi/DB_bots/db_bot.py index 335ccc5..fb4489a 100644 --- a/newapi/DB_bots/db_bot.py +++ b/newapi/DB_bots/db_bot.py @@ -1,15 +1,4 @@ -""" - -Usage: -# from .db_bot import LiteDB -# db = LiteDB(db_path) -# db.create_table(table_name, fields, pk="id", **kwargs) -# db.show_tables(self) -# db.insert(table_name, data, check=True) -# db.get_data(table_name) -# db.select(table_name, args) - -""" +""" """ # --- from typing import Any, Dict, Iterator, List, Optional diff --git a/newapi/api_client/client.py b/newapi/api_client/client.py index 0863d93..5ff4da1 100644 --- a/newapi/api_client/client.py +++ b/newapi/api_client/client.py @@ -68,11 +68,6 @@ class WikiLoginClient: ``RequestsHandler`` provides the transport/retry layer; this class owns only auth logic, parameter enrichment, and continuation pagination. - - Usage:: - - client = WikiLoginClient(lang="en", family="wikipedia", username="MyBot", password="s3cr3t") - data = client.client_request({"action": "query", "titles": "Python"}) """ # Write actions that need bot=1 and assertuser injected diff --git a/newapi/client_wiki/all_apis.py b/newapi/client_wiki/all_apis.py index 48847d5..fc78a43 100644 --- a/newapi/client_wiki/all_apis.py +++ b/newapi/client_wiki/all_apis.py @@ -13,12 +13,6 @@ class AllAPIS: """ A class that provides access to various API functionalities. - Usage: - from newapi import AllAPIS - main_api = AllAPIS(lang='en', family='wikipedia', username='your_username', password='your_password') - page = main_api.MainPage('Main Page Title') - cat_members = main_api.CatDepth('Category Title') - new_api = main_api.NewApi() """ def __init__( diff --git a/newapi/client_wiki/api_utils/bot_edit/bot_edit_by_time.py b/newapi/client_wiki/api_utils/bot_edit/bot_edit_by_time.py index 5d93a88..772fb74 100644 --- a/newapi/client_wiki/api_utils/bot_edit/bot_edit_by_time.py +++ b/newapi/client_wiki/api_utils/bot_edit/bot_edit_by_time.py @@ -31,7 +31,6 @@ def check_create_time(page, title_page): delay_hours = 3 if create_data.get("timestamp"): - create_time = create_data["timestamp"] ts_c_time = datetime.datetime.strptime(create_time, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=datetime.UTC) diff --git a/newapi/client_wiki/api_utils/handel_errors.py b/newapi/client_wiki/api_utils/handel_errors.py index 6b14b94..0076418 100644 --- a/newapi/client_wiki/api_utils/handel_errors.py +++ b/newapi/client_wiki/api_utils/handel_errors.py @@ -73,7 +73,6 @@ def handle_err( _tt = f"<>{function} ERROR: <>code:{err_code}." # ["protectedpage", "تأخير البوتات 3 ساعات", False] if err_code == "abusefilter-disallowed": - # oioioi = {'error': {'code': 'abusefilter-disallowed', 'info': 'This', 'abusefilter': {'id': '169', 'description': 'تأخير البوتات 3 ساعات', 'actions': ['disallow']}, '*': 'See https'}, 'servedby': 'mw1374'} abusefilter = error.get("abusefilter", "") diff --git a/newapi/client_wiki/pages/super_page.py b/newapi/client_wiki/pages/super_page.py index 0ea19ae..79eb2e6 100644 --- a/newapi/client_wiki/pages/super_page.py +++ b/newapi/client_wiki/pages/super_page.py @@ -82,7 +82,6 @@ def client_request( files: Optional[Dict[str, Any]] = None, **kwargs, ) -> Dict[str, Any]: - return self.login_bot.client_request( params, method=method, @@ -309,7 +308,6 @@ def get_infos(self) -> None: self.meta.is_redirect = True if "redirect" in ta else False for cat in ta.get("categories", []): - # _cat_ = { "ns": 14, "title": "تصنيف:بوابة سباق الدراجات الهوائية/مقالات متعلقة", "sortkey": "d8b7", "sortkeyprefix": "", "hidden": True } if "sortkey" in cat: @@ -326,13 +324,11 @@ def get_infos(self) -> None: self.categories_data.categories[category_title] = cat if ta.get("langlinks", []) != []: - # {"lang": "ca", "*": "UCI World Tour 2023"} or {'lang': 'bh', 'title': 'टेम्पलेट:AWB'} self.langlinks = {ta["lang"]: ta.get("*") or ta.get("title") for ta in ta.get("langlinks", [])} if ta.get("templates", []) != []: - # 'templates': [{'ns': 10, 'title': 'قالب:No redirect'}], self.template_data.templates_api = [ta["title"] for ta in ta.get("templates", [])] @@ -425,7 +421,6 @@ def get_extlinks(self): d = 0 while continue_params != {} or d == 0: - d += 1 if continue_params: @@ -508,14 +503,12 @@ def get_langlinks(self): return self.langlinks def get_templates_API(self): - if not self.meta.info["done"]: self.get_infos() return self.template_data.templates_api def get_links_here(self): - if not self.meta.info["done"]: self.get_infos() @@ -752,7 +745,6 @@ def save( return False def purge(self): - params = { "action": "purge", "forcelinkupdate": 1, @@ -978,7 +970,6 @@ def _load_data(body): return self.links_data.links def get_revisions(self, rvprops=None) -> list: - rvprop = [ "comment", "timestamp", diff --git a/newapi/config.py b/newapi/config.py index 2d4bb29..1a24157 100644 --- a/newapi/config.py +++ b/newapi/config.py @@ -176,7 +176,7 @@ class WikiSiteInfo: """Configuration for a wiki site with family and code. Attributes: - family: Wiki family (e.g., "wikipedia", "commons", "wikiquote") + family: wiki family (e.g., "wikipedia", "commons", "wikiquote") code: Language/site code (e.g., "en", "ar", "commons") use: Whether this site is enabled for use """ diff --git a/newapi/core/exceptions.py b/newapi/core/exceptions.py index 3a19959..4105cf5 100644 --- a/newapi/core/exceptions.py +++ b/newapi/core/exceptions.py @@ -8,7 +8,7 @@ from typing import Any, Dict, Optional -class NewApiException(Exception): +class NewApiExceptionError(Exception): """ Base exception for all mw_api errors. @@ -21,7 +21,7 @@ def __init__(self, message: str = "", code: str = "") -> None: super().__init__(message) -class ApiError(NewApiException): +class ApiError(NewApiExceptionError): """ Exception for MediaWiki API errors. @@ -172,7 +172,7 @@ def __init__( super().__init__(code="badtoken", message=message, is_retryable=True, raw_error=raw_error) -class AuthenticationError(NewApiException): +class AuthenticationError(NewApiExceptionError): """ Exception for authentication failures. """ @@ -181,7 +181,7 @@ def __init__(self, message: str = "Authentication failed.") -> None: super().__init__(message, code="auth_failed") -class ValidationError(NewApiException): +class ValidationError(NewApiExceptionError): """ Exception for validation errors in input data. """ diff --git a/newapi/page.py b/newapi/page.py index 9c8cabb..2a2bc8e 100644 --- a/newapi/page.py +++ b/newapi/page.py @@ -7,30 +7,6 @@ from .config import settings from .super.S_API import bot_api -MainPage_DEPRECATION_WARNING = """ - NewApi is deprecated. Please use: - from api_page import load_main_api - api = load_main_api("en", "wikipedia") - page = api.MainPage('title') -""" - -CatDepth_DEPRECATION_WARNING = """ - NewApi is deprecated. Please use: - from api_page import load_main_api - api = load_main_api("en", "wikipedia") - cat_members = api.CatDepth('Category Title', depth=0, ns=10, nslist=[], ...) -""" - -NEW_API_DEPRECATION_WARNING = """ - NewApi is deprecated. Please use: - from api_page import load_main_api - api = load_main_api("en", "wikipedia") - new_api = api.NewApi() - result = new_api.Get_All_pages(start="!", namespace=0, ...) -""" - -# def deprecated(msg): - @functools.lru_cache(maxsize=1) def _load_credentials() -> tuple[str, str]: @@ -58,7 +34,6 @@ def load_main_api(lang, family: str = "wikipedia") -> AllAPIS: ) -# @deprecated(MainPage_DEPRECATION_WARNING) def MainPage(title, lang, family: str = "wikipedia"): # --- main_bot = load_main_api(lang, family) @@ -68,7 +43,6 @@ def MainPage(title, lang, family: str = "wikipedia"): return page -# @deprecated(CatDepth_DEPRECATION_WARNING) def CatDepth(title, sitecode: str = "", family: str = "wikipedia", **kwargs): # --- main_bot = load_main_api(sitecode, family) @@ -78,7 +52,6 @@ def CatDepth(title, sitecode: str = "", family: str = "wikipedia", **kwargs): return result -# @deprecated(NEW_API_DEPRECATION_WARNING) def NewApi(lang: str = "", family: str = "wikipedia") -> bot_api.NewApi: main_bot = load_main_api(lang, family) return main_bot.NewApi() diff --git a/newapi/pformat.py b/newapi/pformat.py index 19edfdc..a4bccc5 100644 --- a/newapi/pformat.py +++ b/newapi/pformat.py @@ -1,16 +1,7 @@ -""" -python3 core8/pwb.py newapi/pformat -""" +""" """ import wikitextparser as wtp -# python3 core8/pwb.py newapi/pformat -title:قالب:Cycling_race/stageclassification3 -# python3 core8/pwb.py newapi/pformat -title:قالب:معلومات_خاصية_ويكي_بيانات/تتبع -# python3 core8/pwb.py newapi/pformat -title: -# python3 core8/pwb.py newapi/pformat -title: -# python3 core8/pwb.py newapi/pformat -title:قالب:Interlanguage_link_multi -# python3 core8/pwb.py newapi/pformat -title:قالب:Cs1_wrapper - def make_new_text(text: str): # --- diff --git a/newapi/super/S_API/bot_api.py b/newapi/super/S_API/bot_api.py index 26ba0e9..02058b5 100644 --- a/newapi/super/S_API/bot_api.py +++ b/newapi/super/S_API/bot_api.py @@ -816,7 +816,6 @@ def _load_data(body): query = body.get("query", {}) return query.get("querypage") or query.get("results") or [] - # --- results = self.login_bot.post_continue_list( params=params, action="query", diff --git a/tests/TestALL_APIS.py b/tests/TestALL_APIS.py index e807714..9544f4c 100644 --- a/tests/TestALL_APIS.py +++ b/tests/TestALL_APIS.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock, patch import pytest + from newapi import AllAPIS diff --git a/tests/TestAuthentication.py b/tests/TestAuthentication.py index c2323b4..301fa1f 100644 --- a/tests/TestAuthentication.py +++ b/tests/TestAuthentication.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock import pytest + from newapi import WikiLoginClient diff --git a/tests/TestLiteDB.py b/tests/TestLiteDB.py index 0936a21..816c823 100644 --- a/tests/TestLiteDB.py +++ b/tests/TestLiteDB.py @@ -2,6 +2,7 @@ import tempfile import pytest + from newapi.DB_bots.db_bot import LiteDB diff --git a/tests/TestMainPage.py b/tests/TestMainPage.py index 71151f9..ded6583 100644 --- a/tests/TestMainPage.py +++ b/tests/TestMainPage.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock, patch import pytest + from newapi.client_wiki.pages.super_page import MainPage diff --git a/tests/TestNewAPI.py b/tests/TestNewAPI.py index 68c1a46..16c402b 100644 --- a/tests/TestNewAPI.py +++ b/tests/TestNewAPI.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock import pytest + from newapi.super.S_API.bot_api import NewApi diff --git a/tests/conftest.py b/tests/conftest.py index 2e7f9c9..4e79ac4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,10 @@ from unittest.mock import MagicMock import pytest -from newapi import WikiLoginClient from pytest_socket import disable_socket +from newapi import WikiLoginClient + @pytest.fixture(autouse=True) def stop_nets(request): diff --git a/tests/unit/api_client/test_client.py b/tests/unit/api_client/test_client.py index b27fe93..b9c2b62 100644 --- a/tests/unit/api_client/test_client.py +++ b/tests/unit/api_client/test_client.py @@ -6,6 +6,7 @@ import mwclient.errors import pytest + from newapi.api_client.client import WikiLoginClient from newapi.api_client.exceptions import LoginError, WikiClientError diff --git a/tests/unit/api_client/test_requests_handler.py b/tests/unit/api_client/test_requests_handler.py index b891c80..53a5d77 100644 --- a/tests/unit/api_client/test_requests_handler.py +++ b/tests/unit/api_client/test_requests_handler.py @@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch import pytest + from newapi.api_client.client import WikiLoginClient from newapi.api_client.exceptions import MaxlagError diff --git a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates.py b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates.py index d6bc165..238c969 100644 --- a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates.py +++ b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates.py @@ -8,6 +8,7 @@ import sys import pytest + from newapi.client_wiki.api_utils.bot_edit.bot_edit_by_templates import ( BOT_USERNAME, STOP_EDIT_TEMPLATES, diff --git a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates2.py b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates2.py index 6ba4adc..9ca562d 100644 --- a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates2.py +++ b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates2.py @@ -12,6 +12,7 @@ from unittest.mock import MagicMock, patch import pytest + from newapi.client_wiki.api_utils.bot_edit.bot_edit_by_templates import ( STOP_EDIT_TEMPLATES, Bot_Cache, diff --git a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates_pypass.py b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates_pypass.py index 088eeef..8f59670 100644 --- a/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates_pypass.py +++ b/tests/unit/api_utils/bot_edit/bot_edit_by_templates/test_bot_edit_by_templates_pypass.py @@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch import pytest + from newapi.client_wiki.api_utils.bot_edit.bot_edit_by_templates import ( Bot_Cache, is_bot_edit_allowed, diff --git a/tests/unit/api_utils/bot_edit/bot_edit_by_time/test_bot_edit_by_time.py b/tests/unit/api_utils/bot_edit/bot_edit_by_time/test_bot_edit_by_time.py index 77ee913..acbe588 100644 --- a/tests/unit/api_utils/bot_edit/bot_edit_by_time/test_bot_edit_by_time.py +++ b/tests/unit/api_utils/bot_edit/bot_edit_by_time/test_bot_edit_by_time.py @@ -4,6 +4,7 @@ import sys import pytest + from newapi.client_wiki.api_utils.bot_edit.bot_edit_by_time import ( check_create_time, check_last_edit_time,