|
import streamlit as st |
|
import pandas as pd |
|
import smtplib |
|
import csv |
|
from email.mime.text import MIMEText |
|
from email.mime.multipart import MIMEMultipart |
|
|
|
data_file = "subscriptions.csv" |
|
|
|
def save_subscription(application_number, email): |
|
"""Save user application number and email to a CSV file.""" |
|
with open(data_file, mode='a', newline='') as file: |
|
writer = csv.writer(file) |
|
writer.writerow([application_number, email]) |
|
|
|
def load_subscriptions(): |
|
"""Load existing subscriptions from CSV.""" |
|
try: |
|
return pd.read_csv(data_file, names=["Application Number", "Email"]) |
|
except FileNotFoundError: |
|
return pd.DataFrame(columns=["Application Number", "Email"]) |
|
|
|
def send_email(to_email, application_number): |
|
"""Send an email notification when the visa is approved.""" |
|
sender_email = "your_email@gmail.com" |
|
sender_password = "your_password" |
|
subject = "Visa Decision Update" |
|
body = f"Your visa application {application_number} has been approved!" |
|
|
|
msg = MIMEMultipart() |
|
msg['From'] = sender_email |
|
msg['To'] = to_email |
|
msg['Subject'] = subject |
|
msg.attach(MIMEText(body, 'plain')) |
|
|
|
try: |
|
server = smtplib.SMTP('smtp.gmail.com', 587) |
|
server.starttls() |
|
server.login(sender_email, sender_password) |
|
server.sendmail(sender_email, to_email, msg.as_string()) |
|
server.quit() |
|
st.success(f"Notification sent to {to_email}") |
|
except Exception as e: |
|
st.error(f"Error sending email: {e}") |
|
|
|
def check_and_notify(approved_list): |
|
"""Check if any subscribed application numbers are in the approved list and send notifications.""" |
|
subscriptions = load_subscriptions() |
|
for index, row in subscriptions.iterrows(): |
|
if row["Application Number"] in approved_list: |
|
send_email(row["Email"], row["Application Number"]) |
|
|
|
|
|
st.title("Visa Notification Subscription") |
|
application_number = st.text_input("Enter Your Application Number") |
|
email = st.text_input("Enter Your Email") |
|
|
|
if st.button("Subscribe"): |
|
if application_number and email: |
|
save_subscription(application_number, email) |
|
st.success("Subscription successful! You will be notified when your decision is updated.") |
|
else: |
|
st.error("Please enter both Application Number and Email.") |
|
|