stopforumspam-checker.py
· 1.2 KiB · Python
Eredeti
# The amount of days within which to check if the user was reported
LAST_SEEN_THRESHOLD = 180
LAST_SEEN_REGEX = r"<lastseen>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})<\/lastseen>"
# The contact name to use in rejection messages
CONTACT = "Admin at admin@example.com"
from urllib.parse import quote_plus
from datetime import datetime
import requests
import re
prompt_data = request.context.get("prompt_data")
if 'email' in prompt_data:
req_url = f"http://api.stopforumspam.org/api?email={quote_plus(prompt_data['email'])}"
if 'username' in prompt_data:
req_url += f"&username={quote_plus(prompt_data['username'])}"
resp = requests.get(req_url)
if resp.status_code != 200:
ak_message(f"There was an error creating your account. Please contact {CONTACT} with the following details: SFS HTTP Error {resp.status_code}")
return False
matches = re.search(LAST_SEEN_REGEX, resp.text)
if matches is None:
return True
last_seen = datetime.strptime(matches.group(1), '%Y-%m-%d %H:%M:%S')
time_elapsed = datetime.now() - last_seen
if time_elapsed.days < LAST_SEEN_THRESHOLD:
ak_message(f"Sorry, we cannot approve your account at this time. Please come back later or contact {CONTACT} if the issue persists.")
return False
return True
1 | # The amount of days within which to check if the user was reported |
2 | LAST_SEEN_THRESHOLD = 180 |
3 | LAST_SEEN_REGEX = r"<lastseen>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})<\/lastseen>" |
4 | |
5 | # The contact name to use in rejection messages |
6 | CONTACT = "Admin at admin@example.com" |
7 | |
8 | from urllib.parse import quote_plus |
9 | from datetime import datetime |
10 | import requests |
11 | import re |
12 | |
13 | prompt_data = request.context.get("prompt_data") |
14 | |
15 | if 'email' in prompt_data: |
16 | req_url = f"http://api.stopforumspam.org/api?email={quote_plus(prompt_data['email'])}" |
17 | if 'username' in prompt_data: |
18 | req_url += f"&username={quote_plus(prompt_data['username'])}" |
19 | |
20 | resp = requests.get(req_url) |
21 | |
22 | if resp.status_code != 200: |
23 | ak_message(f"There was an error creating your account. Please contact {CONTACT} with the following details: SFS HTTP Error {resp.status_code}") |
24 | return False |
25 | |
26 | matches = re.search(LAST_SEEN_REGEX, resp.text) |
27 | if matches is None: |
28 | return True |
29 | |
30 | last_seen = datetime.strptime(matches.group(1), '%Y-%m-%d %H:%M:%S') |
31 | time_elapsed = datetime.now() - last_seen |
32 | if time_elapsed.days < LAST_SEEN_THRESHOLD: |
33 | ak_message(f"Sorry, we cannot approve your account at this time. Please come back later or contact {CONTACT} if the issue persists.") |
34 | return False |
35 | |
36 | return True |
37 |