-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
32 lines (22 loc) · 792 Bytes
/
utils.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
import os
import re
import json
def save_cookies(cookie_value):
# Open the cookies.json file in write mode
with open("cookies.json", "w") as file:
# Write the cookie_value to the file
json.dump(cookie_value, file, indent=4)
def load_cookies():
# Check if the cookies.json file exists
if not os.path.exists("cookies.json"):
return None
# Open the cookies.json file in read mode
with open("cookies.json", "r") as file:
# Load the cookie data
cookie_data = json.load(file)
return cookie_data
def convert_cookies(cookies):
cookies_str = "; ".join([f"{key}={value}" for key, value in cookies.items()])
return cookies_str
def sanitize_filename(filename):
return re.sub(r'[<>:"/\\|?*]', "", filename).strip()