forked from RahulShaw/ITPROTV-DL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
baker.py
28 lines (23 loc) · 1.03 KB
/
baker.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
import json
import os
def bake():
cookies = []
if os.path.exists(os.getcwd() + os.path.sep + "cookies.txt"):
with open('cookies.txt', 'r') as f:
lines = f.readlines()
else:
raise Exception('The "cookies.txt" file was not found')
for line in lines:
if line.startswith('#') or line.startswith('www') or line.startswith('forums') or line.startswith('go') or (len(line.strip()) == 0):
pass
else:
line = line.replace('\n', '').split('\t')
if line.__len__() == 7:
cookie = dict(domain=line[0].strip(), flag=bool((line[1].strip() == 'TRUE')), path=line[2].strip(),
secure=bool((line[3].strip() == 'TRUE')), expiration=line[4].strip(), name=line[5].strip(), value=line[6].strip())
cookies.append(cookie)
else:
raise Exception('Malformed cookies.txt file')
with open('cookies.json', 'w') as f:
f.write(json.dumps(cookies, indent=4))
print("Cookies baked!")