/
run.py
70 lines (55 loc) · 1.96 KB
/
run.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
58
59
60
61
62
63
64
65
66
67
68
69
70
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import os
name = input("Enter Name:")
batch = input("Batch:")
contact = input("Contact No:")
email = input("Enter senders mail:")
num = input("Enter the number of tickets:")
for i in range(1,int(num)+1):
img = Image.open("ticket.jpg")
draw = ImageDraw.Draw(img)
# font = ImageFont.truetype(<font-file>, <font-size>)
font = ImageFont.truetype("adventpro-bold.ttf", 20)
file = open('serial.txt', 'r')
serial = file.read(4)
file.close()
#draw.text((x, y),"Sample Text",(r,g,b))
#Name
draw.text((120, 330),name,(0,0,0),font=font)
#Batch
draw.text((120, 370),batch,(0,0,0),font=font)
#Contact No
draw.text((190, 410),contact,(0,0,0),font=font)
#Slno-1
draw.text((330, 10),serial,(0,0,0),font=font)
#Slno-2
draw.text((1430, 9),serial,(0,0,0),font=font)
img.save('C:/Users/Asus/Desktop/Tickets/tickets/'+name+batch+str(i)+'.jpg')
img.save('output.jpg')
import csv
with open('details.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([serial,name,batch,contact,email])
file = open('serial.txt','w')
serial = int(serial) + 1
file.write(str(serial))
file.close()
from mailsender import MailSender
username = 'youremail@gmail.com'
password = 'password'
sender = username
images = list()
images.append({
'id': 'logo',
'path': 'output.jpg'
})
with open('template.html') as template_html, open('template.txt') as template_plain:
message_html = template_html.read()
message_plain = template_plain.read()
mail_sender = MailSender(username, password)
mail_sender.send(sender, [email], 'Lucky draw ticket.', message_html=message_html, message_plain=message_plain, images=images)
print('..')
os.remove("output.jpg")
print('Email Send')