-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
46 lines (33 loc) · 1.06 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
import os
def create_project_dir(directory):
if not os.path.exists(directory):
print('Creating directory ' + directory)
os.makedirs(directory)
def create_data_files(project_name, base_url):
queue = os.path.join(project_name , 'queue.txt')
crawled = os.path.join(project_name,"crawled.txt")
if not os.path.isfile(queue):
write_file(queue, base_url)
if not os.path.isfile(crawled):
write_file(crawled, '')
def write_file(path, data):
with open(path, 'w') as f:
f.write(data)
def append_to_file(path, data):
with open(path, 'a') as file:
file.write(data + '\n')
def delete_file_contents(path):
open(path, 'w').close()
def file_to_set(file_name):
results = set()
try:
with open(file_name, 'r') as f:
for line in f:
results.add(line.replace('\n', ''))
except FileNotFoundError:
return results
return results
def set_to_file(links, file_name):
with open(file_name,"w") as f:
for l in sorted(links):
f.write(l+"\n")