-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_image_caleg_prov.py
55 lines (43 loc) · 1.7 KB
/
generate_image_caleg_prov.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
42
43
44
45
46
47
48
49
50
51
52
import ssl
import urllib.request
import pandas as pd
import csv
from Constants import *
from util_logging import *
def getImage(id, indexOf, totalData):
is_image_created = False
context = ssl._create_unverified_context()
ssl._create_default_https_context = ssl._create_unverified_context
full_path = BASE_HTML_PATH + "caleg/images/" + id + ".jpg"
try:
print(URL_IMAGE_CALEG.format(id))
urllib.request.urlretrieve(URL_IMAGE_CALEG.format(id), full_path)
message_string = "–––– creating image Caleg DPRD PROV idCaleg={} created –––– ({}/{})".format(id, indexOf, totalData)
is_image_created = True
except Exception as e:
message_string = "ERROR !!! Requesting IMAGE Caleg DPRD PROV idCaleg={} ({}/{})–– {}".format(id, indexOf, totalData, str(e))
is_image_created = False
print(message_string)
pecker(LOG_IMAGE_CALEG, message_string)
return is_image_created
total_data_generated = 0
data_generated = 0
data_error = 0
message_string = "=== START GENERATING IMAGE OF CALEG DPRD PROV ==="
print(message_string)
pecker(LOG_IMAGE_CALEG, message_string)
csv_file = 'data_caleg_prov.csv'
try:
df = pd.read_csv(csv_file)
id_list = df['id'].tolist()
for i,data in enumerate(id_list):
if (getImage(str(data), str(i), str(len(id_list)))):
data_generated += 1
else:
data_error +=1
total_data_generated = data_generated + data_error
message_string = "=== END GENERATING IMAGE OF CALEG DPRD PROV:: generated={}, error={}, total={} data generated, ===".format(data_generated, data_error, total_data_generated)
except Exception as e:
message_string = "ERROR !!! failed generating Caleg DPD PROV image ––{}".format(str(e))
print(message_string)
pecker(LOG_IMAGE_CALEG, message_string)