Log Wikimedia API request metrics
This commit is contained in:
parent
eecbd3cfb8
commit
9486d9cb8a
5 changed files with 268 additions and 16 deletions
|
|
@ -4,6 +4,9 @@ from typing import Any
|
|||
|
||||
import requests
|
||||
|
||||
from .api import wikimedia_log_config
|
||||
from .wikimedia_api_logging import logged_request
|
||||
|
||||
wiki_hostname = "en.wikipedia.org"
|
||||
wiki_api_php = f"https://{wiki_hostname}/w/api.php"
|
||||
user_agent = "dab-mechanic/0.1"
|
||||
|
|
@ -27,8 +30,10 @@ def parse_page(enwiki: str) -> dict[str, Any]:
|
|||
|
||||
def get(params: dict[str, str | int]) -> dict[str, Any]:
|
||||
"""Make GET request to mediawiki API."""
|
||||
data: dict[str, Any] = requests.get(
|
||||
wiki_api_php, headers={"User-Agent": user_agent}, params=params
|
||||
session = requests.Session()
|
||||
session.headers = {"User-Agent": user_agent}
|
||||
data: dict[str, Any] = logged_request(
|
||||
session, wikimedia_log_config, "GET", wiki_api_php, params=params
|
||||
).json()
|
||||
return data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue