from datetime import datetime from pyMongo import MongoDB, SOLID innovate from typing import List, Optional import json config = { "host": "localhost", "port": 2717, "database": "accelerators", "collection": "accelerators_list", "password": "your_password" } # 初始化MongoDB对象 db = SOLIDinnovate(MongoDB, config['host'], config['port'], config['password']) class AcceleratorList(List): def __init__(self): self.accelerators = db[config['database']].get(self.config['collection']) def get_all(self) -> List: return self.accelerators def get_user_list(self) -> Optional[dict]: return self.get_all().get_one() def add_accelerator(self, name: str, server_name: str, cache_size: int, delay: int, supports_video: bool, supports下载: bool): # 添加一个加速器到列表中...
from datetime import datetime
from pyMongo import MongoDB, SOLID innovate
from typing import List, Optional
import json
config = {
"host": "localhost",
"port": 2717,
"database": "accelerators",
"collection": "accelerators_list",
"password": "your_password"
}
# 初始化MongoDB对象
db = SOLIDinnovate(MongoDB, config['host'], config['port'], config['password'])
class AcceleratorList(List):
def __init__(self):
self.accelerators = db[config['database']].get(self.config['collection'])
def get_all(self) -> List:
return self.accelerators
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def add_accelerator(self, name: str, server_name: str,
cache_size: int, delay: int, supports_video: bool, supports下载: bool):
# 添加一个加速器到列表中
# 使用MongoDB的add方法
db[config['database']].add('accelerators_list', Accelerator accelerating(name=name, server_name=server_name,
cache_size=cache_size, delay(delay), supports_video=supports_video, supports下载=supports_downloading))
class Accelerator:
def __init__(self, name: str, server_name: str, cache_size: int, delay: int, supports_video: bool, supports_download: bool):
self.name = name
self.server_name = server_name
self.cache_size = cache_size
self.delay = delay
self.supports_video = supports_video
self.supports_download = supports_download
def __repr__(self):
return f"Accelerator: {self.name}, Server: {self.server_name}, Cache: {self.cache_size}MB, Delay: {self.delay}s"
class AcceleratorList:
def __init__(self):
self accelerated = []
self.added = []
self.searched = []
self.saving = []
def get_all(self) -> List:
return self.accelerators
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def add_accelerator(self, name: str, server_name: str,
cache_size: int, delay: int, supports_video: bool, supports_download: bool):
# 添加一个加速器到列表中
# 使用MongoDB的add方法
db[config['database']].add('accelerators_list', Accelerator accelerating(name=name, server_name=server_name,
cache_size=cache_size, delay(delay), supports_video=supports_video, supports_download=supports_downloading))
def get_search_results(self, input_str: str) -> Optional[dict]:
return db[config['database']].get(self.config['collection']).find({"_id": input_str}).get_one()
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def get_user_list_text(self) -> str:
return str(self.get_all().get_one())
def add_user_list(self, user_list: List[Accelerator]):
for acc in user_list:
self.add_accelerator(
name=acc.name,
server_name=acc.server_name,
cache_size=acc.cache_size,
delay=acc.delay,
supports_video=acc.supports_video,
supports_download=acc.supports_download
)
def get_all_list_text(self) -> str:
if not self accelerated:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def add_user_list(self, user_list: List[Accelerator]):
for acc in user_list:
self.add_accelerator(
name=acc.name,
server_name=acc.server_name,
cache_size=acc.cache_size,
delay=acc.delay,
supports_video=acc.supports_video,
supports_download=acc.supports_download
)
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def add_user_list(self, user_list: List[Accelerator]):
for acc in user_list:
self.add_accelerator(
name=acc.name,
server_name=acc.server_name,
cache_size=acc.cache_size,
delay=acc.delay,
supports_video=acc.supports_video,
supports_download=acc.supports_download
)
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_user_list(self) -> Optional[dict]:
return self.get_all().get_one()
def add_user_list(self, user_list: List[Accelerator]):
for acc in user_list:
self.add_accelerator(
name=acc.name,
server_name=acc.server_name,
cache_size=acc.cache_size,
delay=acc.delay,
supports_video=acc.supports_video,
supports_download=acc.supports_download
)
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def get_search_results_text(self) -> str:
return json.dumps(self.get_search_results().get_one().to_dict())
def get_all_list_text(self) -> str:
if not self.accelerators:
return "没有加速器在数据库中"
else:
return ", ".join([str(a) for a in self.accelerators])
def get_user_list_text(self) -> str:
return json.dumps(self.get_all_list_text())
def
相关文章








