This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
141 lines (106 loc) · 3.87 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
######### Importing Libraries #########
import sys
from os import system
from fpdf import FPDF # necesita install
from datetime import datetime
import locale
import qrcode # necesita install
import ssl, smtplib # necesita install
import cryptocode as cc # necesita install
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
#######################################
######### Setting Locale ##############
locale.setlocale(locale.LC_ALL, 'ro_RO.UTF-8')
#######################################
######### initializare pdf #########
pdf = FPDF('P', 'mm', (127, 127))
pdf.add_page()
####################################
######### adaugare fonturi #########
pdf.add_font('MSSansSerif', '', 'micross.ttf', uni=True)
pdf.add_font('Cascadia', '', 'CascadiaMonoLight.ttf', uni=True)
######### adaugare fonturi #########
######### desenare margini #########
pdf.set_draw_color(106, 32, 192)
pdf.set_line_width(3)
pdf.line(0, 127, 127, 127)
pdf.line(0, 0, 127, 0)
pdf.line(0, 0, 0, 127)
pdf.line(127, 0, 127, 127)
####################################
######### adaugare logo #########
pdf.image("logo.png", w=60, h=60, x=75, y=-10)
pdf.image("zeth.png", x=-10, y=94.5, w=60, h=30)
####################################
######### adaugare header #########
pdf.set_font('MSSansSerif', '', 20)
pdf.cell(0, 10, "BILET", 0, 1, 'L')
pdf.cell(0, 10, "EVENIMENT", 0, 1, 'L')
pdf.set_line_width(1)
pdf.line(12, 35, 117, 35)
####################################
######### body bilet #########
EVENIMENT = sys.argv[1]
DATA = sys.argv[2]
ORA = sys.argv[3]
LOCAȚIE = sys.argv[4]
ZONA = sys.argv[5]
RAND = sys.argv[6]
LOC = sys.argv[7]
UID = sys.argv[8]
QRCODE_UID = qrcode.make(UID)
QRCODE_UID.save(f"qrcode{UID}.png") # ""
DATA_DT = datetime.strptime(DATA, "%d/%m/%Y").strftime("%A %d %B %Y")
pdf.set_font('Cascadia', '', 12)
pdf.cell(0, 25, "EVENIMENT " + EVENIMENT, 0, 1, 'L')
pdf.cell(0, -15, DATA_DT + " " + ORA, 0, 1, 'L')
pdf.cell(0, 25, LOCAȚIE, 0, 1, 'L')
pdf.line(12, 60, 117, 60)
pdf.set_font('Cascadia', '', 15)
pdf.cell(0, 0, "ZONA: " + ZONA, 0, 1, 'L')
pdf.cell(0, 15, f"RAND: {RAND}", 0, 1, 'L')
pdf.cell(0, 0, f"LOC: {LOC}", 0, 1, 'L')
pdf.image(f"qrcode{UID}.png", w=28, h=28, x=85, y=62)
pdf.line(12, 90, 117, 90)
image_addr = f"qrcode{UID}.png"
pdf.set_font('Cascadia', '', 12)
pdf.cell(0, 26.5, "UID: " + UID, 0, 1, 'C')
##############################
######### output #########
pdf.output(f"bilet_{UID}.pdf")
##########################
######### email #########
subject = "🎫 Biletul tău la evenimentul " + EVENIMENT
body = "Bună ziua, \n\nAtașat găsiți biletul dumneavoastră la evenimentul " + EVENIMENT + " din data de " + DATA_DT +\
" la ora " + ORA + ".\n\nVă mulțumim pentru că ați ales să participați la evenimentul nostru!\n\nCu stimă," \
"\nEchipa Zeth Tickets"
sender_email = cc.decrypt(sys.argv[9], sys.argv[12])
password = cc.decrypt(sys.argv[10], sys.argv[12])
receiver_email = sys.argv[11]
message = MIMEMultipart()
message["From"] = formataddr((str(Header('Zeth Tickets', 'utf-8')), sender_email))
message["To"] = receiver_email
message["Subject"] = subject
message.attach(MIMEText(body, "plain"))
filename = f"bilet_{UID}.pdf"
with open(filename, "rb") as attachment:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header(
"Content-Disposition",
f"attachment; filename={filename}",
)
message.attach(part)
text = message.as_string()
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.hostinger.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, text)
system(f'cmd /c "del {filename}"')
system(f'cmd /c "del {image_addr}"')