-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.py
43 lines (31 loc) · 1.17 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
# -----------------------------------
# @CreateTime : 2020/2/9 1:37
# @Author : Mark Shawn
# @Email : [email protected]
# ------------------------------------
import json
import logging
logger_common = logging.getLogger("LOGGER_COMMON")
logger_common.setLevel(logging.DEBUG)
class Cookie:
@staticmethod
def cookie_jar2dict(cookie_jar: list) -> dict:
return dict((i["name"], i["value"]) for i in cookie_jar)
@staticmethod
def cookie_jar2str(cookie_jar: list) -> str:
return "".join(["{}={};".format(i["name"], i["value"]) for i in cookie_jar])
@staticmethod
def cookie_dict2str(cookie_dict: dict) -> str:
return "".join(["{}={};".format(i, j) for i, j in cookie_dict.items()])
@staticmethod
def cookie_str2dict(cookie_str: str) -> dict:
return dict(i.split("=", 1) for i in cookie_str.split(";") if i)
class Json:
@staticmethod
def read_json(json_file: str) -> [list, dict]:
return json.load(open(json_file, "redis", encoding="utf-8"))
@staticmethod
def save_json(json_data: [list, dict], save_to_path: str) -> None:
json.dump(json_data, open(save_to_path, "w", encoding="utf-8"),
ensure_ascii=False, indent=4)