mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
30 minute cache for false
This commit is contained in:
parent
c345242997
commit
79d6f86784
@ -9,6 +9,7 @@ from .Tools import read_directory_json_to_dict
|
|||||||
import os
|
import os
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Sherlock():
|
class Sherlock():
|
||||||
@ -27,11 +28,15 @@ class Sherlock():
|
|||||||
|
|
||||||
for social_network in list(valid_usernames_dict.keys()):
|
for social_network in list(valid_usernames_dict.keys()):
|
||||||
self.dict[social_network] = valid_usernames_dict[social_network]
|
self.dict[social_network] = valid_usernames_dict[social_network]
|
||||||
self.dict[social_network]["cache"] = []
|
self.dict[social_network]["cache"] = dict()
|
||||||
|
|
||||||
def check_network(self, username, social_network):
|
def check_network(self, username, social_network):
|
||||||
|
|
||||||
if username in self.dict[social_network]["cache"]:
|
if username in list(self.dict[social_network]["cache"].keys()):
|
||||||
|
if not self.dict[social_network]["cache"][username]["exists"]:
|
||||||
|
if time.time() - self.dict[social_network]["cache"][username]["time"] <= 1800:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
url = self.dict.get(social_network).get("url").format(username)
|
url = self.dict.get(social_network).get("url").format(username)
|
||||||
@ -63,8 +68,11 @@ class Sherlock():
|
|||||||
if error in r.url:
|
if error in r.url:
|
||||||
user_exists = False
|
user_exists = False
|
||||||
|
|
||||||
|
if username not in list(self.dict[social_network]["cache"].keys()):
|
||||||
|
self.dict[social_network]["cache"][username] = {}
|
||||||
|
self.dict[social_network]["cache"][username]["time"] = time.time()
|
||||||
|
self.dict[social_network]["cache"][username]["exists"] = user_exists
|
||||||
if user_exists:
|
if user_exists:
|
||||||
self.dict[social_network]["cache"].append(username)
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user