-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
57 lines (45 loc) · 1.54 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import xlrd
import smtplib
import os
import sys
import logging
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from config.credentials import *
from func.sender import sender
from func.maker import maker
def put_data():
error_list = []
error_count = 0
# Read data from an excel sheet from row 2
abspath = os.path.abspath("")
data_dir = os.path.join(abspath, "data")
Book = xlrd.open_workbook(f'{data_dir}/data.xlsx')
WorkSheet = Book.sheet_by_name('Sheet1')
num_row = WorkSheet.nrows - 1
row = 0
#Set the level of log messages to INFO
logging.basicConfig(level=logging.INFO)
while row < num_row:
row += 1
ID = WorkSheet.cell_value( row, 0 )
name = WorkSheet.cell_value( row, 1 )
institute = WorkSheet.cell_value( row, 2 )
receiver = WorkSheet.cell_value( row, 3 )
title = WorkSheet.cell_value( row, 4 )
# Make certificate and check if it was successful
filepath , filename = maker( ID, name, institute, title )
# Successfully made certificate
if filepath != -1 and sender( filepath, filename, receiver ):
logging.info(f'Sent to {ID}')
else:
error_list.append( ID )
error_count += 1
# Log of errors
if error_count==0:
logging.info(f'Errors = {error_count}')
else:
logging.warning(f'Errors = {error_count} \nList Of IDs for which error occured : ' + ','.join(error_list))
if __name__ == "__main__":
put_data()