-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (35 loc) · 1.1 KB
/
main.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
import os
def create_projectdir(directory):
if not os.path.exists(directory):
print("Creating Directory.. " + directory)
os.makedirs(directory)
else:
print("Directory Already Exists!!")
def write_file(path, data):
with open(path, 'w') as f:
f.writelines(data)
# create_projectdir('websites')
def createdatafiles(proj_name, base_url):
queue = proj_name + '/queues.txt'
crawled = proj_name + '/crawles.txt'
if not os.path.isfile(queue):
write_file(queue, base_url)
if not os.path.exists(crawled):
write_file(crawled, '')
def append_to_file(path, data):
with open(path, 'a') as f:
f.write(data + '\n')
def delete_file_contents(path):
with open(path, 'w'):
pass
# createdatafiles('websites', 'https://jjnanthakumar.github.io/')
def file_to_set(fname):
data = set()
with open(fname, 'rt') as f:
for line in f:
data.add(line.replace('\n', ''))
return data
def set_to_file(links, file):
delete_file_contents(file)
for link in sorted(links):
append_to_file(file, link)