mirror of
https://github.com/lanqian528/chat2api.git
synced 2026-06-13 21:02:46 +08:00
112 lines
2.6 KiB
Python
112 lines
2.6 KiB
Python
import json
|
|
import os
|
|
|
|
import ua_generator
|
|
import random
|
|
|
|
from utils.Logger import logger
|
|
|
|
DATA_FOLDER = "data"
|
|
TOKENS_FILE = os.path.join(DATA_FOLDER, "token.txt")
|
|
REFRESH_MAP_FILE = os.path.join(DATA_FOLDER, "refresh_map.json")
|
|
ERROR_TOKENS_FILE = os.path.join(DATA_FOLDER, "error_token.txt")
|
|
WSS_MAP_FILE = os.path.join(DATA_FOLDER, "wss_map.json")
|
|
USER_AGENTS_FILE = os.path.join(DATA_FOLDER, "user_agents.json")
|
|
SEED_MAP_FILE = os.path.join(DATA_FOLDER, "seed_map.json")
|
|
CONVERSATION_MAP_FILE = os.path.join(DATA_FOLDER, "conversation_map.json")
|
|
|
|
count = 0
|
|
token_list = []
|
|
error_token_list = []
|
|
refresh_map = {}
|
|
wss_map = {}
|
|
user_agent_map = {}
|
|
seed_map = {}
|
|
conversation_map = {}
|
|
impersonate_list = [
|
|
"chrome99",
|
|
"chrome100",
|
|
"chrome101",
|
|
"chrome104",
|
|
"chrome107",
|
|
"chrome110",
|
|
"chrome116",
|
|
"chrome119",
|
|
"chrome120",
|
|
"chrome123",
|
|
"edge99",
|
|
"edge101",
|
|
]
|
|
|
|
if not os.path.exists(DATA_FOLDER):
|
|
os.makedirs(DATA_FOLDER)
|
|
|
|
if os.path.exists(REFRESH_MAP_FILE):
|
|
with open(REFRESH_MAP_FILE, "r") as f:
|
|
try:
|
|
refresh_map = json.load(f)
|
|
except:
|
|
refresh_map = {}
|
|
else:
|
|
refresh_map = {}
|
|
|
|
if os.path.exists(WSS_MAP_FILE):
|
|
with open(WSS_MAP_FILE, "r") as f:
|
|
try:
|
|
wss_map = json.load(f)
|
|
except:
|
|
wss_map = {}
|
|
else:
|
|
wss_map = {}
|
|
|
|
|
|
if os.path.exists(USER_AGENTS_FILE):
|
|
with open(USER_AGENTS_FILE, "r", encoding="utf-8") as f:
|
|
try:
|
|
user_agent_map = json.load(f)
|
|
except:
|
|
user_agent_map = {}
|
|
else:
|
|
user_agent_map = {}
|
|
|
|
|
|
if os.path.exists(SEED_MAP_FILE):
|
|
with open(SEED_MAP_FILE, "r") as f:
|
|
try:
|
|
seed_map = json.load(f)
|
|
except:
|
|
seed_map = {}
|
|
else:
|
|
seed_map = {}
|
|
|
|
|
|
if os.path.exists(CONVERSATION_MAP_FILE):
|
|
with open(CONVERSATION_MAP_FILE, "r") as f:
|
|
try:
|
|
conversation_map = json.load(f)
|
|
except:
|
|
conversation_map = {}
|
|
else:
|
|
conversation_map = {}
|
|
|
|
|
|
if os.path.exists(TOKENS_FILE):
|
|
with open(TOKENS_FILE, "r", encoding="utf-8") as f:
|
|
for line in f:
|
|
if line.strip() and not line.startswith("#"):
|
|
token_list.append(line.strip())
|
|
else:
|
|
with open(TOKENS_FILE, "w", encoding="utf-8") as f:
|
|
pass
|
|
|
|
|
|
if os.path.exists(ERROR_TOKENS_FILE):
|
|
with open(ERROR_TOKENS_FILE, "r", encoding="utf-8") as f:
|
|
for line in f:
|
|
if line.strip() and not line.startswith("#"):
|
|
error_token_list.append(line.strip())
|
|
else:
|
|
with open(ERROR_TOKENS_FILE, "w", encoding="utf-8") as f:
|
|
pass
|
|
|