-
Notifications
You must be signed in to change notification settings - Fork 1
/
replies.py
70 lines (53 loc) · 2.13 KB
/
replies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import re
import urllib
WIKI_URL = 'https://en.wikipedia.org/wiki/{}'
VISIT_URL = 'https://www.visitacity.com/en/{}/activities/all-activities'
MAPS_URL = 'https://www.google.com/maps/search/{}'
BOOKING_URL = 'https://www.booking.com/searchresults.sl.html?ss={}'
WANDER_URL = 'http://www.wandermap.net/sl/search/?q={}'
TB_URL = 'https://www.tumblr.com/search/{}'
PT_URL = 'https://www.pinterest.com/search/pins/?q={}'
FOOTER = '\n\n---\n\n^(I am a bot and this was an automated message. I am not responsible for the content neither am ' \
'I an author of this content. If you think this message is problematic, please contact developers mentioned ' \
'below.)\n\n^(Author: [u/mtj510](https://www.reddit.com/user/mtj510) | [how to use this bot](' \
'https://github.com/matej2/location-info/blob/master/README.md#example) | [github](' \
'https://github.com/matej2/location-info) ) '
NO_BODY = 'Location name not found in comment body.'
LOC_NOT_FOUND = 'No summary found for {}. Either unknown location or mistype.'
SPACE_REGEX = '\s+'
def get_visit_link(txt):
parsed = re.sub(SPACE_REGEX, '-', txt)
return VISIT_URL.format(parsed)
def get_map_link(txt):
parsed = re.sub(SPACE_REGEX, '+', txt)
return MAPS_URL.format(parsed)
def get_booking_url(txt):
parsed = re.sub(SPACE_REGEX, '+', txt)
return BOOKING_URL.format(parsed)
def get_wander_url(txt):
parsed = re.sub(SPACE_REGEX, '+', txt)
return WANDER_URL.format(parsed)
def get_th_url(txt):
parsed = re.sub(SPACE_REGEX, '+', txt)
return TB_URL.format(parsed)
def get_pt_url(txt):
parsed = urllib.parse.quote_plus(txt)
return PT_URL.format(parsed)
def get_response_message(city, msg, link, nearby):
if city is None:
message = f'''
{msg}
{FOOTER}
'''
else:
message = f'''
Information for location: {city}:\n\n {msg} \n\n
- locations/events nearby: {nearby}\n\n
- links: [wiki]({link})
~[map]({get_map_link(city)})
~ [hotels]({get_booking_url(city)})
~ [hiking]({get_wander_url(city)})
~ [thumblr]({get_th_url(city)})
~ [pinterest]({get_pt_url(city)})
{FOOTER}'''
return message