forked from Ruturaj4/Search-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse_keeping.py
38 lines (32 loc) · 846 Bytes
/
house_keeping.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
# Name: house_keeping
# Author: Ruturaj Kiran Vaidya
# Date: 17 May 2018
import os
def create_data_files(base_url):
#Create two files
queue = 'queue.txt'
crawled = 'crawled.txt'
if not os.path.isfile(queue):
write_file(queue, base_url)
if not os.path.isfile(crawled):
write_file(crawled, '')
#We will use this to write in the file
def write_file(path, data):
f = open(path, 'w')
f.write(data)
f.close
#Read a file and convert each line to set items
def toSet(filename):
#Using set to save the result
results = set()
with open(filename, 'rt') as f:
for line in f:
results.add(line.replace('\n',''))
return results
#Iterate through a set, each item will be a new line in the file
def writeInFile(links, file):
with open(file, 'w'):
pass
for link in sorted(links):
with open(file, 'a') as f:
f.write(link + '\n')