# The amount of days within which to check if the user was reported LAST_SEEN_THRESHOLD = 180 LAST_SEEN_REGEX = r"(\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