Skip to content
Merged

. #151

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
13 changes: 1 addition & 12 deletions newapi/DB_bots/db_bot.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions newapi/api_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions newapi/client_wiki/all_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
1 change: 0 additions & 1 deletion newapi/client_wiki/api_utils/bot_edit/bot_edit_by_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion newapi/client_wiki/api_utils/handel_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def handle_err(
_tt = f"<<lightred>>{function} ERROR: <<default>>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", "")
Expand Down
9 changes: 0 additions & 9 deletions newapi/client_wiki/pages/super_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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", [])]
Expand Down Expand Up @@ -425,7 +421,6 @@ def get_extlinks(self):
d = 0

while continue_params != {} or d == 0:

d += 1

if continue_params:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -752,7 +745,6 @@ def save(
return False

def purge(self):

params = {
"action": "purge",
"forcelinkupdate": 1,
Expand Down Expand Up @@ -978,7 +970,6 @@ def _load_data(body):
return self.links_data.links

def get_revisions(self, rvprops=None) -> list:

rvprop = [
"comment",
"timestamp",
Expand Down
2 changes: 1 addition & 1 deletion newapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
8 changes: 4 additions & 4 deletions newapi/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Dict, Optional


class NewApiException(Exception):
class NewApiExceptionError(Exception):
"""
Base exception for all mw_api errors.

Expand All @@ -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.

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
"""
Expand Down
27 changes: 0 additions & 27 deletions newapi/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
11 changes: 1 addition & 10 deletions newapi/pformat.py
Original file line number Diff line number Diff line change
@@ -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):
# ---
Expand Down
1 change: 0 additions & 1 deletion newapi/super/S_API/bot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/TestALL_APIS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock, patch

import pytest

from newapi import AllAPIS


Expand Down
1 change: 1 addition & 0 deletions tests/TestAuthentication.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock

import pytest

from newapi import WikiLoginClient


Expand Down
1 change: 1 addition & 0 deletions tests/TestLiteDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile

import pytest

from newapi.DB_bots.db_bot import LiteDB


Expand Down
1 change: 1 addition & 0 deletions tests/TestMainPage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock, patch

import pytest

from newapi.client_wiki.pages.super_page import MainPage


Expand Down
1 change: 1 addition & 0 deletions tests/TestNewAPI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock

import pytest

from newapi.super.S_API.bot_api import NewApi


Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/api_client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import mwclient.errors
import pytest

from newapi.api_client.client import WikiLoginClient
from newapi.api_client.exceptions import LoginError, WikiClientError

Expand Down
1 change: 1 addition & 0 deletions tests/unit/api_client/test_requests_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading