-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (35 loc) · 1.02 KB
/
app.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
# -*- coding: utf-8 -*-
import json
import sys
from multiprocessing.dummy import Pool as ThreadPool
from avito import Avito
from drom import Drom
from youla import Youla
def grab(task):
print(task)
if task["module"] == "avito":
avito = Avito(task)
avito.grab()
elif task["module"] == "youla":
youla =Youla(task)
youla.grab()
elif task["module"] == "drom":
drom =Drom(task)
drom.grab()
else:
print("Module {} not found.".format(task["module"]))
if len(sys.argv) == 1:
print("Configuration file not provided")
quit()
configuration_file = sys.argv[1]
print("Configuration file: {}".format(configuration_file))
with open(configuration_file, mode="r", encoding="utf-8") as f:
configurationStr = f.read()
# Загружаем файл конфигурации
configuration = json.loads(configurationStr)
tasks = configuration['tasks']
# Готовим пул
pool = ThreadPool(configuration["threadCount"])
pool.map(grab, tasks)
pool.close()
pool.join()