forked from jvdburgh/AmputatorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_funcs.py
More file actions
56 lines (45 loc) · 1.95 KB
/
basic_funcs.py
File metadata and controls
56 lines (45 loc) · 1.95 KB
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
#from helpers.criteria_checker import check_criteria
from helpers.utils import get_urls, get_urls_info
from helpers.utils import check_if_amp
def generate_message(links):
# Initialize all variables
canonical_text_latest, canonical_text_list, canonical_text = "", "", ""
n_canonicals = 0
# Loop through all links, and generate the canonical link part of the comment
for link in links:
if link.is_amp:
if link.canonical:
n_canonicals += 1
canonical_text_latest += link.canonical
canonical_text_list += f"[{n_canonicals}] {link.canonical}\n"
if n_canonicals >= 1:
if n_canonicals == 1:
intro_who_wat = "It looks like you shared a cached AMP link. These should load faster, but Google's " \
"AMP is controversial because of concerns over privacy and the Open Web: " \
"https://reddit.com/r/AmputatorBot/comments/ehrq3z/why_did_i_build_amputatorbot/ "
intro_maybe = "\n\nYou might want to visit the uncached page instead: "
canonical_text = canonical_text_latest
else:
intro_who_wat = "It looks like you shared some cached AMP links. "
intro_maybe = "You might want to visit the uncached pages instead: "
canonical_text = canonical_text_list
tweet_text = intro_who_wat + intro_maybe + canonical_text
return tweet_text
return None
def get_reply(message):
if not check_if_amp(message):
return message
urls = get_urls(message)
links = get_urls_info(urls)
if any(link.is_amp for link in links):
return generate_message(links)
def get_replacement_array(message):
if not check_if_amp(message):
return []
urls = get_urls(message)
links = get_urls_info(urls)
array=[]
for link in links:
if link.canonical:
array.append((link.url, link.canonical))
return array