Add User-Agent to mediawiki API calls

This commit is contained in:
Edward Betts 2022-08-17 14:38:30 +01:00
parent 4e1ad4efbc
commit 5f8900a47a
3 changed files with 55 additions and 41 deletions

View file

@ -12,7 +12,7 @@ from requests_oauthlib import OAuth1Session
from werkzeug.debug.tbtools import get_current_traceback
from werkzeug.wrappers import Response
from dab_mechanic import wikidata_oauth, wikipedia
from dab_mechanic import mediawiki_api, wikidata_oauth, wikipedia
app = flask.Flask(__name__)
app.config.from_object("config.default")
@ -47,21 +47,6 @@ def exception_handler(e):
)
def get_content(title: str) -> str:
"""Get article text."""
params: dict[str, str | int] = {
"action": "query",
"format": "json",
"formatversion": 2,
"prop": "revisions|info",
"rvprop": "content|timestamp",
"titles": title,
}
data = requests.get(wiki_api_php, params=params).json()
rev: str = data["query"]["pages"][0]["revisions"][0]["content"]
return rev
def parse_articles_with_dab_links(root: lxml.html.Element) -> list[tuple[str, int]]:
"""Parse Articles With Multiple Dablinks."""
articles = []
@ -127,7 +112,7 @@ def save(enwiki: str) -> Response | str:
edit_summary = f"Disambiguate {titles} using [[User:Edward/Dab mechanic]]"
article_text = apply_edits(get_content(enwiki), edits)
article_text = apply_edits(mediawiki_api.get_content(enwiki), edits)
return flask.render_template(
"save.html",