示例#1
0
def save_cookies(cookie: dict) -> None:
    from src.func.encryptor import Encryptor
    encryptor = Encryptor()
    key = encryptor.load_key(get_key_path())
    data = encryptor.encrypt_str(key, str(cookie))
    with open(os.path.join(get_data_dir(), 'user.cookies'), 'wb') as f:
        pickle.dump(data, f)
示例#2
0
def load_cookies() -> dict:
    with open(os.path.join(get_data_dir(), 'user.cookies'), 'rb') as f:
        encrypted_cookie = pickle.load(f)
    if is_key_exists():
        try:
            from src.func.encryptor import Encryptor
            encryptor = Encryptor()
            key = encryptor.load_key(get_key_path())
            string = encryptor.decrypt_data(key,
                                            encrypted_cookie).decode('utf-8')
            res = literal_eval(string)
        except (AssertionError, AttributeError):
            res = {}
    else:
        res = {}
    return res
示例#3
0
def is_key_exists(key_file: str = '.wgr.key') -> bool:
    return os.path.exists(os.path.join(get_data_dir(), key_file))
示例#4
0
def get_key_path(key_file: str = '.wgr.key') -> str:
    return os.path.join(get_data_dir(), key_file)
示例#5
0
def get_qsettings_file() -> str:
    return os.path.join(get_data_dir(), 'wgviewer.ini')
示例#6
0
def del_key_file(key_file: str = '.wgr.key') -> None:
    if is_key_exists(key_file):
        os.remove(os.path.join(get_data_dir(), key_file))
    else:
        pass