1
|
from Utilities import FolderProcessor
|
2
|
from Utilities.Crawler import BasicCrawlerFunctions
|
3
|
|
4
|
# Path to crawled data
|
5
|
CRAWLED_DATA_PATH = "CrawledData/"
|
6
|
|
7
|
|
8
|
def crawl(config):
|
9
|
"""
|
10
|
Implement crawl method that downloads new data to path_for_files
|
11
|
For keeping the project structure
|
12
|
url , regex, and dataset_name from config
|
13
|
You can use already implemented functions from Utilities/Crawler/BasicCrawlerFunctions.py
|
14
|
|
15
|
Args:
|
16
|
config: loaded configuration file of dataset
|
17
|
"""
|
18
|
dataset_name = config["dataset-name"]
|
19
|
url = config['url']
|
20
|
regex = config['regex']
|
21
|
path_for_files = CRAWLED_DATA_PATH + dataset_name + '/'
|
22
|
|
23
|
first_level_links = BasicCrawlerFunctions.get_all_links(url)
|
24
|
filtered_first_level_links = BasicCrawlerFunctions.filter_links(first_level_links, "^OD_ZCU")
|
25
|
absolute_first_level_links = BasicCrawlerFunctions.create_absolute_links(filtered_first_level_links, url)
|
26
|
|
27
|
files = []
|
28
|
|
29
|
for link in absolute_first_level_links:
|
30
|
second_level_links = BasicCrawlerFunctions.get_all_links(link)
|
31
|
filtered_second_level_links = BasicCrawlerFunctions.filter_links(second_level_links, regex)
|
32
|
absolute_second_level_links = BasicCrawlerFunctions.create_absolute_links(filtered_second_level_links, link)
|
33
|
final_links = BasicCrawlerFunctions.remove_downloaded_links(absolute_second_level_links, dataset_name)
|
34
|
|
35
|
for file_link in final_links:
|
36
|
files.append(file_link)
|
37
|
|
38
|
for file in files:
|
39
|
BasicCrawlerFunctions.download_file_from_url(file, dataset_name)
|
40
|
|
41
|
FolderProcessor.unzip_all_csv_zip_files_in_folder(path_for_files)
|