simplify UrlPoolManager to use a set instead of a dict

This commit is contained in:
2018-08-29 21:49:15 +01:00
parent fb096b4468
commit 2b812da26a

View File

@@ -9,28 +9,22 @@ class UrlPoolManager(object):
'''
def __init__(self):
self.url_pool = dict()
self.not_crawled = 0
self.crawled = 1
self.invalid = 2
self.url_pool = set()
def check_duplicate(self, new_url):
for url, status in self.url_pool.items():
if url == new_url:
return True
else:
return False
'''
Checks if a URL exists in the current pool.
'''
if new_url in self.url_pool:
return True
else:
return False
def invalidate_url(self, url):
self.url_pool[url] = self.invalid
self.url_pool.remove(url)
def add_to_list(self, url):
self.url_pool[url] = self.not_crawled
# calculate depth
# add link, crawled status to url_pool
def mark_as_crawled(self, url):
self.url_pool[url] = self.crawled
self.url_pool.add(url)
def clean_base_url(url):