-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
50 lines (31 loc) · 1.02 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
def save_to_file_url(url, r, file_path, postfix):
if not os.path.exists(file_path):
os.makedirs(file_path)
file_name = get_file_name(url, postfix)
with open(file_path + file_name, 'wb+') as f:
f.write(r.content)
def save_to_file(path, file_name, content, once=False):
if not os.path.exists(path):
os.makedirs(path)
path = path + file_name
if os.path.exists(path) and once:
return
#print(content)
with open(path, 'w+') as f:
f.write(content)
def save_to_file_append(path, file_name, content):
if not os.path.exists(path):
os.makedirs(path)
path = path + file_name
# if os.path.exists(path):
# return
with open(path, 'a+') as f:
f.write(content)
def get_file_name(url, postfix='html'):
file_name = url.split("/")[-1]
if file_name == 'review_all':
file_name = url.split("/")[-2] + '_' + file_name
if '.' not in file_name:
file_name = file_name + '.' + postfix
return file_name