Skip to content

Commit

Permalink
Added docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
matej2 committed Jan 16, 2025
1 parent f6a0ae2 commit 9797e09
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
28 changes: 23 additions & 5 deletions WikiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = ''
Expand All @@ -77,4 +95,4 @@ def get_taxonomy(title):
value=re.sub('\\n', '', param.value.strip())
)
parsed_params.append(add_par)
return parsed_params
return parsed_params
4 changes: 3 additions & 1 deletion const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})'
2 changes: 1 addition & 1 deletion manual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from main import main_stream

if __name__ == '__main__':
main_stream()
main_stream()
15 changes: 8 additions & 7 deletions replies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 9797e09

Please sign in to comment.