From 9797e09651fb4527882d0059eab861cf329bd93f Mon Sep 17 00:00:00 2001 From: matej2 <11059438+matej2@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:58:56 +0100 Subject: [PATCH] Added docstring --- WikiClient.py | 28 +++++++++++++++++++++++----- const.py | 4 +++- manual.py | 2 +- replies.py | 15 ++++++++------- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/WikiClient.py b/WikiClient.py index 3a464d8..3842fb9 100644 --- a/WikiClient.py +++ b/WikiClient.py @@ -5,13 +5,19 @@ import requests import wikipedia from mwparserfromhell.nodes.extras import Parameter +from wikipedia import WikipediaPage from models import LocationMeta class WikiClient: @staticmethod - def get_location_meta(city): + def get_location_meta(city: str): + """ + Get location metadata + :return: + LocationMeta: Meta data + """ search = wikipedia.search(city) st = 0 @@ -37,20 +43,32 @@ def get_location_meta(city): return None @staticmethod - def is_location(page): + def is_location(page: WikipediaPage): + """ + :return: + bool: True if page is a location + """ for attr in page.categories: if attr == 'Coordinates on Wikidata': return True return False @staticmethod - def get_nearby_locations(lon, lat): + def get_nearby_locations(lon: str, lat: str): + """ + :return: + str: A list of nearby locations + """ loc_list = wikipedia.geosearch(lon, lat, results=10) return ', '.join(loc_list) # See https://stackoverflow.com/a/33336820/10538678 @staticmethod - def get_taxonomy(title): + def get_taxonomy(title: str): + """ + :return: + list[Parameter]: A list of parameters + """ infobox = None parsed_params = [] a = '' @@ -77,4 +95,4 @@ def get_taxonomy(title): value=re.sub('\\n', '', param.value.strip()) ) parsed_params.append(add_par) - return parsed_params \ No newline at end of file + return parsed_params diff --git a/const.py b/const.py index 06802d9..9784eed 100644 --- a/const.py +++ b/const.py @@ -32,11 +32,13 @@ class Const: @staticmethod def successfully_processed(city: str): """ - :param city: str :return: str """ return f'{city} successfully processed' @staticmethod def body_regex(mention: str): + """ + :return: str + """ return f'{mention}\s*({Const.CITY_REGEX})' diff --git a/manual.py b/manual.py index 9a00c10..db95480 100644 --- a/manual.py +++ b/manual.py @@ -1,4 +1,4 @@ from main import main_stream if __name__ == '__main__': - main_stream() \ No newline at end of file + main_stream() diff --git a/replies.py b/replies.py index 412c576..d9ad598 100644 --- a/replies.py +++ b/replies.py @@ -12,37 +12,38 @@ TB_URL = 'https://www.tumblr.com/search/{}' PT_URL = 'https://www.pinterest.com/search/pins/?q={}' -def get_visit_link(txt): + +def get_visit_link(txt: str): parsed = re.sub(Const.SPACE_REGEX, '-', txt) return VISIT_URL.format(parsed) -def get_map_link(txt): +def get_map_link(txt: str): parsed = re.sub(Const.SPACE_REGEX, '+', txt) return MAPS_URL.format(parsed) -def get_booking_url(txt): +def get_booking_url(txt: str): parsed = re.sub(Const.SPACE_REGEX, '+', txt) return BOOKING_URL.format(parsed) -def get_wander_url(txt): +def get_wander_url(txt: str): parsed = re.sub(Const.SPACE_REGEX, '+', txt) return WANDER_URL.format(parsed) -def get_th_url(txt): +def get_th_url(txt: str): parsed = re.sub(Const.SPACE_REGEX, '+', txt) return TB_URL.format(parsed) -def get_pt_url(txt): +def get_pt_url(txt: str): parsed = urllib.parse.quote_plus(txt) return PT_URL.format(parsed) -def get_response_message(city, msg, nearby: Optional[str]): +def get_response_message(city: str, msg: str, nearby: Optional[str]): if city is None: message = f''' {msg}