-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (25 loc) · 846 Bytes
/
Copy pathmain.py
File metadata and controls
34 lines (25 loc) · 846 Bytes
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
from threading import Thread, Lock
from src import XMLtoObjectConvertor, FileProcessor,\
WebSiteLoader, PageParser, GoodsStorage
def parse(desc):
loader = loader = WebSiteLoader(desc)
while not loader.is_all_pages_loaded():
page = loader.get_next_page()
goods = PageParser.parse(page, desc.paths, desc.trash)
lock.acquire()
storage.extend(goods)
lock.release()
del loader
storage = GoodsStorage()
lock = Lock()
input_data = FileProcessor.read('input.xml')
sites = XMLtoObjectConvertor.convert(input_data)
threads = []
for site_desc in sites.getchildren():
thread = Thread(target=parse, args=(site_desc,))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
output_data = storage.to_XML_string()
FileProcessor.write('output.xml', output_data)