You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dcs/conf/config.py

86 lines
2.1 KiB

from collections import deque
from typing import Any
class CUI:
def __init__(self, user_name, login_time, login_state, state, cookie, address):
self.user_name = user_name
self.login_time = login_time
self.login_state = login_state
self.state = state
self.cookie = cookie
self.address = address
self.crawl_result = deque()
class global_var:
"""需要定义全局变量的放在这里"""
connection = None
free_spiders = []
current_user_info: list[CUI] = [CUI('god', None, None, None, 'god', None)]
requester = None
server = None
spider = None
up = None
communicator = None
server_socket = None
configs = None
test = None
def get_free_addresses() -> tuple[Any, ...]:
fs = []
for i in global_var.current_user_info:
if i.state == 'free':
fs.append(i.address)
return tuple(fs)
def exists(cookie):
for i in global_var.current_user_info:
if i.cookie == cookie:
return True
return False
def add_user(user_name, login_time, login_state, state, cookie, address=None):
global_var.current_user_info.append(CUI(user_name, login_time, login_state, state, cookie, address))
def set_state_client(cookie, state=None, address=None):
if address:
for i in global_var.current_user_info:
if i.address == address:
i.state = state
break
return
for i in global_var.current_user_info:
if i.cookie == cookie:
i.state = state
break
def set_crawl_result(cookie, result):
for i in global_var.current_user_info:
if i.cookie == cookie:
i.crawl_result.append(result)
break
def get_crawl_result(cookie):
for i in global_var.current_user_info:
if i.cookie == cookie:
return i.crawl_result
def get_by_cookie(cookie):
for i in global_var.current_user_info:
if i.cookie == cookie:
return i
return None
def delete_user(cookie):
i = get_by_cookie(cookie)
global_var.current_user_info.remove(i)