|
|
@ -10,42 +10,38 @@ class ValidTester(object): |
|
|
|
self.cookies_db = RedisClient('cookies', self.name) |
|
|
|
self.cookies_db = RedisClient('cookies', self.name) |
|
|
|
self.account_db = RedisClient('accounts', self.name) |
|
|
|
self.account_db = RedisClient('accounts', self.name) |
|
|
|
|
|
|
|
|
|
|
|
def test(self, account, cookies): |
|
|
|
def test(self, username, cookies): |
|
|
|
raise NotImplementedError |
|
|
|
raise NotImplementedError |
|
|
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
def run(self): |
|
|
|
accounts = self.cookies_db.all() |
|
|
|
cookies_groups = self.cookies_db.all() |
|
|
|
print(accounts) |
|
|
|
for username, cookies in cookies_groups.items(): |
|
|
|
for account in accounts: |
|
|
|
self.test(username, cookies) |
|
|
|
username = account.get('username') |
|
|
|
|
|
|
|
cookies = self.cookies_db.get(username) |
|
|
|
|
|
|
|
self.test(account, cookies) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WeiboValidTester(ValidTester): |
|
|
|
class WeiboValidTester(ValidTester): |
|
|
|
def __init__(self, name='weibo'): |
|
|
|
def __init__(self, name='weibo'): |
|
|
|
ValidTester.__init__(self, name) |
|
|
|
ValidTester.__init__(self, name) |
|
|
|
|
|
|
|
|
|
|
|
def test(self, account, cookies): |
|
|
|
def test(self, username, cookies): |
|
|
|
print('Testing Account', account.get('username')) |
|
|
|
print('正在测试Cookies', '用户名', username) |
|
|
|
try: |
|
|
|
try: |
|
|
|
cookies = json.loads(cookies) |
|
|
|
cookies = json.loads(cookies) |
|
|
|
except TypeError: |
|
|
|
except TypeError: |
|
|
|
print('Invalid Cookies Value', account.get('username')) |
|
|
|
print('Cookies不合法', username) |
|
|
|
self.cookies_db.delete(account.get('username')) |
|
|
|
self.cookies_db.delete(username) |
|
|
|
print('Deleted User', account.get('username')) |
|
|
|
print('删除Cookies', username) |
|
|
|
return None |
|
|
|
return |
|
|
|
try: |
|
|
|
try: |
|
|
|
test_url = TEST_URL_MAP[self.name] |
|
|
|
test_url = TEST_URL_MAP[self.name] |
|
|
|
response = requests.get(test_url, cookies=cookies, timeout=5, allow_redirects=False) |
|
|
|
response = requests.get(test_url, cookies=cookies, timeout=5, allow_redirects=False) |
|
|
|
if response.status_code == 200: |
|
|
|
if response.status_code == 200: |
|
|
|
print('Valid Cookies', account.get('username')) |
|
|
|
print('Cookies有效', username) |
|
|
|
|
|
|
|
print('部分测试结果', response.text[0:50]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
print(response.status_code, response.headers) |
|
|
|
print(response.status_code, response.headers) |
|
|
|
print('Invalid Cookies', account.get('username')) |
|
|
|
print('Cookies失效', username) |
|
|
|
self.cookies_db.delete(account.get('username')) |
|
|
|
self.cookies_db.delete(username) |
|
|
|
print('Deleted User', account.get('username')) |
|
|
|
print('删除Cookies', username) |
|
|
|
except ConnectionError as e: |
|
|
|
except ConnectionError as e: |
|
|
|
print('Error', e.args) |
|
|
|
print('发生异常', e.args) |
|
|
|
print('Invalid Cookies', account.get('username')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|