Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
·
74a29fd
1
Parent(s):
41bc6bd
get logos in main.py
Browse filesSigned-off-by: Niv Sardi <xaiki@evilgiggle.com>
- python/imtool.py +1 -0
- python/main.py +3 -0
- python/vendor.py +7 -6
- python/web.py +3 -2
python/imtool.py
CHANGED
@@ -99,6 +99,7 @@ def mix(a, b, fx, fy):
|
|
99 |
x = math.floor(fx*(aw - bw))
|
100 |
y = math.floor(fy*(ah - bh))
|
101 |
|
|
|
102 |
mat = a[y:y+bh,x:x+bw]
|
103 |
cols = b[:, :, :3]
|
104 |
alpha = b[:, :, 3]/255
|
|
|
99 |
x = math.floor(fx*(aw - bw))
|
100 |
y = math.floor(fy*(ah - bh))
|
101 |
|
102 |
+
# handle transparency
|
103 |
mat = a[y:y+bh,x:x+bw]
|
104 |
cols = b[:, :, :3]
|
105 |
alpha = b[:, :, 3]/255
|
python/main.py
CHANGED
@@ -5,6 +5,7 @@ import shutil
|
|
5 |
from bs4 import BeautifulSoup
|
6 |
from progress.bar import ChargingBar
|
7 |
|
|
|
8 |
from entity import Entity
|
9 |
from common import selectors, defaults, mkdir
|
10 |
|
@@ -28,6 +29,8 @@ with open(f'{defaults.MAIN_CSV_PATH}.tmp', 'w', newline='') as csvfile:
|
|
28 |
try:
|
29 |
img = soup.select_one(selectors.logosbancos).attrs['src']
|
30 |
img = img.replace('../', 'https://www.bcra.gob.ar/')
|
|
|
|
|
31 |
except AttributeError as err:
|
32 |
print('img', name, err)
|
33 |
img = None
|
|
|
5 |
from bs4 import BeautifulSoup
|
6 |
from progress.bar import ChargingBar
|
7 |
|
8 |
+
import web
|
9 |
from entity import Entity
|
10 |
from common import selectors, defaults, mkdir
|
11 |
|
|
|
29 |
try:
|
30 |
img = soup.select_one(selectors.logosbancos).attrs['src']
|
31 |
img = img.replace('../', 'https://www.bcra.gob.ar/')
|
32 |
+
fn = f"{defaults.LOGOS_DATA_PATH}/{bco}.0.png"
|
33 |
+
web.get_img_logo(img, fn)
|
34 |
except AttributeError as err:
|
35 |
print('img', name, err)
|
36 |
img = None
|
python/vendor.py
CHANGED
@@ -10,17 +10,18 @@ from common import defaults,mkdir
|
|
10 |
import screenshot
|
11 |
import web
|
12 |
|
|
|
|
|
13 |
def query_vendor_site(e: Entity):
|
14 |
-
page = web.get_page(e)
|
15 |
fn = web.get_cert(e)
|
16 |
-
lfn = web.get_logos(e
|
17 |
-
screenshot.sc_entity(e)
|
18 |
-
return (fn, lfn)
|
19 |
|
20 |
-
def from_csv(fn):
|
21 |
with open(fn, newline='') as csvfile:
|
22 |
reader = csv.DictReader(csvfile)
|
23 |
-
with concurrent.futures.ThreadPoolExecutor(max_workers =
|
24 |
futures = {executor.submit(query_vendor_site, e): e for e in [Entity.from_dict(d) for d in reader]}
|
25 |
bar = ChargingBar('Processing', max=len(futures))
|
26 |
for f in concurrent.futures.as_completed(futures):
|
|
|
10 |
import screenshot
|
11 |
import web
|
12 |
|
13 |
+
PARALLEL = 20
|
14 |
+
|
15 |
def query_vendor_site(e: Entity):
|
|
|
16 |
fn = web.get_cert(e)
|
17 |
+
lfn = web.get_logos(e)
|
18 |
+
sfn = screenshot.sc_entity(e)
|
19 |
+
return (fn, lfn, sfn)
|
20 |
|
21 |
+
def from_csv(fn: str):
|
22 |
with open(fn, newline='') as csvfile:
|
23 |
reader = csv.DictReader(csvfile)
|
24 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers = PARALLEL) as executor:
|
25 |
futures = {executor.submit(query_vendor_site, e): e for e in [Entity.from_dict(d) for d in reader]}
|
26 |
bar = ChargingBar('Processing', max=len(futures))
|
27 |
for f in concurrent.futures.as_completed(futures):
|
python/web.py
CHANGED
@@ -34,7 +34,8 @@ def get_img_logo(src: str, fn):
|
|
34 |
shutil.copyfileobj(res.raw, f)
|
35 |
return fn
|
36 |
|
37 |
-
def get_logos(e: Entity
|
|
|
38 |
soup = BeautifulSoup(page.content, "html.parser")
|
39 |
logos = soup.select(selectors.img_logo)
|
40 |
logos.extend(soup.select(selectors.id_logo))
|
@@ -42,7 +43,7 @@ def get_logos(e: Entity, page):
|
|
42 |
|
43 |
mkdir.make_dirs([defaults.LOGOS_DATA_PATH])
|
44 |
|
45 |
-
i =
|
46 |
lfn = []
|
47 |
for l in logos:
|
48 |
if 'src' in l.attrs:
|
|
|
34 |
shutil.copyfileobj(res.raw, f)
|
35 |
return fn
|
36 |
|
37 |
+
def get_logos(e: Entity):
|
38 |
+
page = get_page(e)
|
39 |
soup = BeautifulSoup(page.content, "html.parser")
|
40 |
logos = soup.select(selectors.img_logo)
|
41 |
logos.extend(soup.select(selectors.id_logo))
|
|
|
43 |
|
44 |
mkdir.make_dirs([defaults.LOGOS_DATA_PATH])
|
45 |
|
46 |
+
i = 1
|
47 |
lfn = []
|
48 |
for l in logos:
|
49 |
if 'src' in l.attrs:
|