-
Notifications
You must be signed in to change notification settings - Fork 7
/
image_extracting_script.py
51 lines (37 loc) · 1.27 KB
/
image_extracting_script.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
import pandas as pd
import wget
import smtplib
import sys
# function to extract images in a directory
def url_to_jpg(ID,file_path,file_name):
img_format = '.jpg'
full_path = '{}{}{}'.format(file_path, file_name, img_format)
wget.download(f'https://docs.google.com/uc?export=download&id={ID}', out = full_path)
# function to send email
def send_mail(sender_mail,sender_pass,recipient_mail,message):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(sender_mail,sender_pass)
server.sendmail(sender_mail,recipient_mail,message)
smtpserver.quit()
# get csv_file name
csv_file = sys.argv[1];
data = pd.read_csv(csv_file)
size = data['upload image'].shape[0]
# path where the images will be store after downloading
file_path = sys.argv[2]
# get the images download from each link
for i in range(size):
ID = data['upload image'].iloc[i].split('=')[-1]
file_name = data['email'].iloc[i]
url_to_jpg(ID,file_path,file_name)
# sender email id
sender_mail = sys.argv[3]
# sender email password
sender_pass = sys.argv[4]
for i in range(size):
recipient_mail = data['email'].iloc[i]
# message = model prediction
send_mail(sender_mail,sender_pass,recipient_mail,message)