Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
•
cf048df
1
Parent(s):
4b45b50
python/vendor: use REST api for screenshoting
Browse files- python/vendor.py +22 -15
python/vendor.py
CHANGED
@@ -7,32 +7,39 @@ from progress.bar import ChargingBar
|
|
7 |
|
8 |
from entity import Entity
|
9 |
from common import defaults,mkdir
|
10 |
-
import screenshot
|
11 |
import web
|
12 |
|
13 |
PARALLEL = 20
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def from_csv(fn: str, n_workers = PARALLEL):
|
|
|
22 |
with open(fn, newline='') as csvfile:
|
23 |
reader = csv.DictReader(csvfile)
|
24 |
with concurrent.futures.ThreadPoolExecutor(max_workers = n_workers) as executor:
|
25 |
-
futures = {
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
for f in concurrent.futures.as_completed(futures):
|
28 |
-
|
29 |
try:
|
30 |
-
|
31 |
-
except Exception as
|
32 |
-
print('
|
33 |
-
raise
|
34 |
-
else:
|
35 |
-
print(cert, logos)
|
36 |
bar.next()
|
37 |
bar.finish()
|
38 |
|
|
|
7 |
|
8 |
from entity import Entity
|
9 |
from common import defaults,mkdir
|
|
|
10 |
import web
|
11 |
|
12 |
PARALLEL = 20
|
13 |
|
14 |
+
def do_screenshot(e: Entity):
|
15 |
+
sfn = requests.post('http://puppet:8000/screenshot', json={
|
16 |
+
'url': e.url,
|
17 |
+
'id': e.id,
|
18 |
+
'path': f'{defaults.SCREENSHOT_PATH}/{e.bco}.png',
|
19 |
+
'logos': f'{defaults.LOGOS_DATA_PATH}/{e.bco}.png'
|
20 |
+
})
|
21 |
+
|
22 |
+
ACTIONS = [web.get_cert, web.get_logos, do_screenshot]
|
23 |
|
24 |
def from_csv(fn: str, n_workers = PARALLEL):
|
25 |
+
mkdir.make_dirs([defaults.SCREENSHOT_PATH])
|
26 |
with open(fn, newline='') as csvfile:
|
27 |
reader = csv.DictReader(csvfile)
|
28 |
with concurrent.futures.ThreadPoolExecutor(max_workers = n_workers) as executor:
|
29 |
+
futures = {}
|
30 |
+
entities = [Entity.from_dict(d) for d in reader]
|
31 |
+
bar = ChargingBar('vendor', max=len(entities*len(ACTIONS)))
|
32 |
+
|
33 |
+
for e in entities:
|
34 |
+
futures.update({executor.submit(f, e): (e, f) for f in ACTIONS})
|
35 |
+
print('waiting for futures')
|
36 |
+
|
37 |
for f in concurrent.futures.as_completed(futures):
|
38 |
+
(e, a) = futures[f]
|
39 |
try:
|
40 |
+
f.result()
|
41 |
+
except Exception as err:
|
42 |
+
print(f'{a}({e.url}) generated an exception: {err}')
|
|
|
|
|
|
|
43 |
bar.next()
|
44 |
bar.finish()
|
45 |
|