Types and docstrings.
This commit is contained in:
parent
b12a89c3b6
commit
5c934e19bc
|
@ -13,6 +13,8 @@ commons_url = "https://www.wikidata.org/w/api.php"
|
||||||
wikidata_api = "https://www.wikidata.org/w/api.php"
|
wikidata_api = "https://www.wikidata.org/w/api.php"
|
||||||
user_agent = "conference-archive/0.1 (contact: edward@4angle.com)"
|
user_agent = "conference-archive/0.1 (contact: edward@4angle.com)"
|
||||||
|
|
||||||
|
CallParams = dict[str, str | int]
|
||||||
|
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s.headers.update({"User-Agent": user_agent})
|
s.headers.update({"User-Agent": user_agent})
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ def search(q: str) -> list[dict[str, typing.Any]]:
|
||||||
|
|
||||||
def api_image_detail_call(filename: str) -> requests.Response:
|
def api_image_detail_call(filename: str) -> requests.Response:
|
||||||
"""Call the Commons API."""
|
"""Call the Commons API."""
|
||||||
call_params = {
|
call_params: CallParams = {
|
||||||
"format": "json",
|
"format": "json",
|
||||||
"formatversion": 2,
|
"formatversion": 2,
|
||||||
"action": "query",
|
"action": "query",
|
||||||
|
@ -102,6 +104,7 @@ def download_photo(filename: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def get_photo(filename: str) -> None:
|
def get_photo(filename: str) -> None:
|
||||||
|
"""Download filename and resize."""
|
||||||
save_to = os.path.join("static", "wikidata_photo", filename)
|
save_to = os.path.join("static", "wikidata_photo", filename)
|
||||||
thumb = os.path.join("static", "wikidata_photo", "thumb", filename)
|
thumb = os.path.join("static", "wikidata_photo", "thumb", filename)
|
||||||
if not os.path.exists(save_to):
|
if not os.path.exists(save_to):
|
||||||
|
|
Loading…
Reference in a new issue