Skip to content

Commit 5344188

Browse files
committed
2 parents 9b27ec1 + 1dcdbe8 commit 5344188

File tree

10 files changed

+402
-22
lines changed

10 files changed

+402
-22
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Automate-Emails-Daily/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import smtplib
2+
import ssl
3+
import os
4+
from email.message import EmailMessage
5+
from email.utils import formataddr
6+
7+
def send_email(sender_email: str,
8+
sender_name: str,
9+
password:str,
10+
receiver_emails: str ,
11+
email_body: str,
12+
email_subject: str="No subject",)-> None:
13+
14+
msg = EmailMessage()
15+
msg["Subject"] = email_subject
16+
msg["From"] = formataddr((f"{sender_name}", f"{sender_email}"))
17+
msg["BCC"] = sender_email
18+
msg.set_content(email_body)
19+
20+
smtp_port = 587
21+
smtp_server = "smtp.gmail.com"
22+
23+
# Adding ssl layer of security
24+
ssl_context = ssl.create_default_context()
25+
26+
try:
27+
# Creating smtp server
28+
print("Connecting to Server...")
29+
my_server = smtplib.SMTP(smtp_server, smtp_port)
30+
my_server.starttls(context=ssl_context)
31+
32+
# Login to smtp server
33+
my_server.login(sender_email, password)
34+
print("Connected to server!")
35+
36+
# Sending email
37+
print(f"Sending email from: {sender_email}")
38+
print("**************************************")
39+
for receiver in receiver_emails:
40+
msg["To"] = receiver
41+
print(f"Sending email to: {receiver}")
42+
my_server.sendmail(sender_email, receiver, msg.as_string())
43+
print(f"...\nSuccessfully sent to: {receiver}")
44+
print("**************************************")
45+
del msg["To"]
46+
except Exception as e:
47+
print(f"ERROR: {e}")
48+
finally:
49+
my_server.quit()
50+
51+
# change these variables to suite your requirements
52+
sender_email = "[email protected]"
53+
sender_name = "your name"
54+
password = os.environ.get("EMAIL_PASSWORD")
55+
56+
email_subject = "good morning"
57+
email_body = "good morning, hope you have a wonderful day"
58+
59+
60+
61+
send_email(sender_email, sender_name, password, receiver_emails, email_body,email_subject)

Merge of images.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

QR Ticket Generator/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#QR Ticket Generator from Excel File
2+
3+
This project is a QR ticket generator that converts data from an Excel file into QR codes for ticket generation.
4+
5+
6+
###Features
7+
8+
9+
1. Read data from an Excel file.
10+
11+
2. Generate QR codes based on the data.
12+
13+
3. Save QR codes as image files.
14+
15+
4. Print tickets with QR codes.
16+
17+
###Contributing
18+
19+
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
20+

QR Ticket Generator/main.py

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
import qrcode
2+
import pandas as pd
3+
from email.mime.multipart import MIMEMultipart
4+
from email.mime.text import MIMEText
5+
from email.mime.application import MIMEApplication
6+
import smtplib
7+
import os
8+
from fpdf import FPDF
9+
# gmail auth
10+
gmail_user = '[email protected]'
11+
gmail_password = 'jydbwqtbfvwwrdpv'
12+
13+
FILEPATH = "InsertDataHERE.xlsx"
14+
15+
16+
def send_ticket(email, full_name, registration_number, event_name, pdf_dir):
17+
try:
18+
msg = MIMEMultipart()
19+
msg['From'] = gmail_user
20+
msg['To'] = email
21+
msg['Subject'] = 'Event Ticket'
22+
# Add text to the email body
23+
text = MIMEText(f"Hey {full_name},"
24+
f"\n PFA of your event {event_name} Ticket"
25+
f"\n We hope you enjoy the event!")
26+
msg.attach(text)
27+
# # Add an image attachment to the email
28+
# with open('image.jpg', 'rb') as f:
29+
# img = MIMEImage(f.read())
30+
# msg.attach(img)
31+
# Add a pdf attachment to the email
32+
fileName = pdf_dir
33+
with open(fileName, 'rb') as f:
34+
pdf = MIMEApplication(f.read(), _subtype='pdf')
35+
pdf.add_header('content-disposition', 'attachment', filename=os.path.basename(fileName))
36+
msg.attach(pdf)
37+
# Create the SMTP server and send the email
38+
server = smtplib.SMTP('smtp.gmail.com', 587)
39+
server.starttls()
40+
server.login(gmail_user, gmail_password)
41+
server.send_message(msg)
42+
server.quit()
43+
44+
except:
45+
print(f"{registration_number}-{full_name} Failed to send mail")
46+
47+
48+
def make_qr(full_name: str, registration_number: str, unique_id: str, event_name: str):
49+
try:
50+
51+
print(f"{registration_number}-{full_name} QR successfully generated")
52+
53+
# Making QR code
54+
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
55+
qr.add_data(unique_id)
56+
qr.make(fit=True)
57+
58+
# Saving QR in respective directory
59+
img = qr.make_image(fill_color="black", back_color="white")
60+
qrcode_dir = f"{registration_number}.png"
61+
img.save(qrcode_dir)
62+
63+
print(f"{registration_number}-{full_name} QR Code saved here:- {qrcode_dir}")
64+
65+
return qrcode_dir
66+
except:
67+
print(f"{registration_number}-{full_name} Failed to generate QR for ")
68+
69+
70+
class PDF(FPDF):
71+
def __init__(self):
72+
super().__init__(format='A5', orientation='L')
73+
74+
def header(self):
75+
# Arial bold 15
76+
self.set_font('Arial', 'B', 15)
77+
# Move to the right
78+
self.cell(80)
79+
# Title
80+
self.cell(30, 10, 'Entry Pass')
81+
# Line break
82+
self.ln(20)
83+
84+
def heading(self, EVENT_NAME):
85+
self.cell(80)
86+
# Font
87+
self.set_font("Arial", 'B', 40)
88+
# Event name
89+
self.cell(30, 30, EVENT_NAME, 0, 0, 'C')
90+
91+
def date_time_venue(self, DATE_TIME_EVENT, VENUE_EVENT):
92+
self.cell(40)
93+
# Font
94+
self.set_font("Arial", 'B', 10)
95+
# DATE_TIME_VENUE
96+
self.cell(-110, 76, DATE_TIME_EVENT, 0, 0, 'C')
97+
self.cell(110, 88, VENUE_EVENT, 0, 0, 'C')
98+
99+
def attendee_name(self, PER_NAME):
100+
self.set_y(70)
101+
self.set_font("Arial", 'B', 25)
102+
# ATTENDEE NAME
103+
self.cell(60, 50, PER_NAME, 0, 0, 'L')
104+
# self.cell(65, 58, ROLE, 0, 0, 'C')
105+
106+
def role_in_event(self, ROLE):
107+
self.set_y(76)
108+
self.set_font("Arial", 'I', 10)
109+
# Role in Event
110+
self.cell(60, 52, f"ROLE: {ROLE}", 0, 0, 'L')
111+
112+
def payment_status(self, PAYMENT):
113+
self.set_y(-37)
114+
self.set_font("Arial", '', 10)
115+
# Payment Status
116+
self.cell(0, 10, PAYMENT, 0, 0, 'L')
117+
118+
def order_number(self, order_no):
119+
self.set_x(-75)
120+
self.set_font("Arial", '', 10)
121+
# Order Number
122+
self.cell(0, 10, f"Order Number: {order_no}", 0, 0, 'L')
123+
124+
def get_qr_code(self, file_path: str):
125+
self.image(name=file_path, x=155, y=85, w=25, h=25)
126+
127+
# Page footer
128+
def footer(self):
129+
# Position at 1.5 cm from bottom
130+
self.set_y(-15)
131+
# Arial italic 8
132+
self.set_font('Arial', 'I', 8)
133+
# Page number
134+
self.cell(0, 10, 'Page ' + str(self.page_no()) + '/{nb}', 0, 0, 'C')
135+
136+
137+
def generate_pdf(event_name: str, full_name: str, role: str, payment_status: str,
138+
unique_id: str, qrcode_dir: str, registration_number: str,
139+
date_time_event='28 February 2023, 4PM to 7PM', venue_event='location_hehe'):
140+
try:
141+
142+
pdf = PDF()
143+
pdf.alias_nb_pages()
144+
pdf.add_page()
145+
pdf.set_font('Times', '', 12)
146+
pdf.heading(EVENT_NAME=event_name)
147+
pdf.date_time_venue(DATE_TIME_EVENT=date_time_event, VENUE_EVENT=venue_event)
148+
pdf.attendee_name(PER_NAME=full_name)
149+
pdf.role_in_event(ROLE=role)
150+
pdf.payment_status(PAYMENT=payment_status)
151+
pdf.order_number(order_no=unique_id)
152+
pdf.get_qr_code(qrcode_dir)
153+
154+
pdf_dir = f"{registration_number}.pdf"
155+
156+
pdf.output(pdf_dir)
157+
158+
print(f"{registration_number}-{full_name} PDF saved here:- {pdf_dir}")
159+
os.remove(f"{registration_number}.png")
160+
return pdf_dir
161+
162+
except Exception as e:
163+
print(e)
164+
165+
166+
def start_entry_process():
167+
# collection = connectToDatabase()
168+
df = pd.read_excel(FILEPATH)
169+
confirm_payment_df = df[df['payment status'] == 'captured']
170+
failed_payment_df = df[df['payment status'] == 'failed']
171+
172+
for index in range(0, len(confirm_payment_df)):
173+
# try:
174+
175+
registration_number = confirm_payment_df['registration_number'].iloc[index].upper()
176+
unique_id = confirm_payment_df['order_id'].iloc[index]
177+
event_name = confirm_payment_df['payment button title'].iloc[index]
178+
email = confirm_payment_df['email'].iloc[index]
179+
full_name = confirm_payment_df['full_name'].iloc[index].upper()
180+
gender = confirm_payment_df['gender'].iloc[index].upper()
181+
role = "ATTENDEE"
182+
payment_status = "PAID"
183+
document = {
184+
"registration_number": registration_number,
185+
"full_name": full_name,
186+
"unique_id": unique_id,
187+
"event_name": event_name,
188+
"email": email,
189+
"gender": gender,
190+
"role": role,
191+
"payment_status": payment_status,
192+
"isInside": False
193+
}
194+
try:
195+
196+
qrcode_dir = make_qr(full_name, registration_number, unique_id, event_name)
197+
pdf_dir = generate_pdf(event_name, full_name, role, payment_status,
198+
unique_id, qrcode_dir, registration_number)
199+
200+
send_ticket(email, full_name, registration_number, event_name, pdf_dir)
201+
202+
except Exception as e:
203+
print(e)
204+
print(f"{registration_number}-{full_name} Already in database")
205+
206+
207+
if __name__ == '__main__':
208+
start_entry_process()

QR Ticket Generator/requirements.txt

464 Bytes
Binary file not shown.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ More information on contributing and the general code of conduct for discussion
8181
| Planet Simulation | [Planet Simulation](https://github.com/DhanushNehru/Python-Scripts/tree/master/planetSimulation) | A simulation of several planets rotating around the sun. |
8282
| Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. |
8383
| ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/ROCK-PAPER-SCISSOR) | A game of Rock Paper Scissors. |
84+
| Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values!
8485
| Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and mails you when it completes execution. |
8586
| Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie_with_Python) | Take your selfie with python . |
8687
| Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! |

Random Color Generator/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# How to Run
2+
- Make sure you have python 3.8.10 installed
3+
- Make sure you have pygame installed \(How to install [Pygame](#how-to-install-pygame)\)
4+
- Extract Random Color Generator.zip
5+
- Run the program with
6+
```markdown
7+
./Random Color Generator> python RandColorGen.py
8+
```
9+
10+
# How to use
11+
- Click on the window to change colors
12+
- The color values are logged in the console and shown on screen
13+
14+
# How to Install Pygame
15+
- After installing python
16+
- Use pip to install Pygame
17+
```markdown
18+
./wherever> pip install pygame
19+
```
20+
21+
## Dependencies:
22+
- random library
23+
- math library
24+
- pygame library
25+

0 commit comments

Comments
 (0)