Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用指定配置文件时可以保存多个cookie #75

Open
wants to merge 1 commit into
base: browser
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def __init__(self):
}

self.jobs_skip = []
self.name = ''

@classmethod
def load(cls, d):
def load(cls, d,file_name):
the_config = Config()

the_config.debug = d.get('debug', False)
Expand All @@ -47,6 +48,8 @@ def load(cls, d):

the_config.jobs_skip = d.get('jobs_skip', [])

the_config.name = file_name.split('.', 1)[0]

return the_config


Expand Down Expand Up @@ -74,7 +77,8 @@ def load_config():
except Exception as e:
sys.exit('# 错误: 配置文件载入失败: {}'.format(e))

the_config = Config.load(config_dict)
# 读取配置时传入配置文件名
the_config = Config.load(config_dict,config_name)

return the_config

Expand Down
14 changes: 12 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def make_session() -> requests.Session:
'User-Agent': config.ua
})

data_file = Path(__file__).parent.joinpath('../data/cookies')
# 根据配置文件名找对应cookie
if(config.name != ''):
data_file = Path(__file__).parent.joinpath('../data/cookies' + config.name)
else:
data_file = Path(__file__).parent.joinpath('../data/cookies')

if data_file.exists():
try:
Expand All @@ -67,7 +71,13 @@ def save_session(session):

data_dir = Path(__file__).parent.joinpath('../data/')
data_dir.mkdir(exist_ok=True)
data_file = data_dir.joinpath('cookies')

# 根据配置文件名取对应cookie
if (config.name != ''):
data_file = data_dir.joinpath('cookies' + config.name)
else:
data_file = data_dir.joinpath('cookies')

data_file.write_bytes(data)


Expand Down