-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
41 lines (28 loc) · 898 Bytes
/
utils.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
import re
keywords = ["gambling",
"casino",
"betting",
"poker",
"lottery",
"drug",
"cocaine",
"marijuana",
"heroin",
"narcotics",
]
def filter_content(redis_connection, content):
filtering_keywords = redis_connection.smembers('filtering_keywords')
for keyword in filtering_keywords:
if keyword in content:
print(keyword)
return False
return True
BLOCKED_URLS = 'blocked_urls'
def is_url_blocked(redis_connection, url):
return redis_connection.sismember('blocked_urls', url)
def validate_and_sanitize_url(url):
url_pattern = re.compile(r'^https?://[^\s/$.?#].[^\s]*$')
if url_pattern.match(url):
return 200, url.strip()
else:
return 400, None