File size: 5,965 Bytes
47519fe
7e83bb3
726f903
 
937e1fb
374128d
 
399eb3e
09589d8
47519fe
0aeae1d
2373e69
 
db82224
0aeae1d
9e487b1
 
 
0aeae1d
 
 
 
 
4a10b2b
4797da8
 
0aeae1d
4797da8
0aeae1d
 
 
 
 
 
4a10b2b
0aeae1d
b6b9d88
0aeae1d
 
 
 
 
 
 
c1c1ee1
0aeae1d
a5e8bc7
 
 
 
 
 
 
 
 
 
 
 
4469432
 
 
 
 
 
 
 
 
 
 
 
 
 
09589d8
 
 
 
 
 
 
 
 
 
 
 
0aeae1d
47519fe
0aeae1d
 
9e487b1
 
 
0aeae1d
09589d8
 
0aeae1d
09589d8
0aeae1d
 
 
 
 
 
 
 
 
e8b3a0a
399eb3e
0aeae1d
 
 
9e487b1
 
 
 
 
 
 
f64da6a
47519fe
a5e8bc7
04023a6
47519fe
 
 
a5e8bc7
f56f210
5f8cd96
47519fe
9e487b1
 
 
 
 
eb5ae80
47519fe
a5e8bc7
47519fe
 
 
04023a6
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
import gradio as gr
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
import qrcode
from PIL import Image
import io
import numpy as np
import datetime

# Set global variables
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
HOST_EMAIL = os.getenv('HOST_EMAIL')
DISCORD_LINK = os.getenv('DISCORD_LINK')

# Add a set to track submitted emails
submitted_emails = set()

# Function to create email content
def create_email_content(name, email, question, event_date, event_time, rsvp_timestamp):
    base_content = f'''
        <p>Thank you for your RSVP, {name}. You are registered for the AI Study Group event on {event_date} from {event_time}.</p>
        <p>Discord link to join the group: {DISCORD_LINK}</p>
        <pre>
        {discord_instructions_markdown}

        FUBAR Labs - New Jersey's First Hackerspace
        "Where fun is learning and work is fun."
        
        Explore: [FUBAR Labs Website](https://fubarlabs.org)
        Support Us: [Donate Here](https://fubarlabs.org/donate)
        
        FUBAR Labs | 1510B Jersey Avenue, North Brunswick, NJ 08902
        Phone: 732-50-FUBAR | Email: info@fubarlabs.org
        </pre>
    '''
    question_content = f"<p>Your question for the AI Study Group: {question}</p>" if question else "<p>No specific questions for this session.</p>"
    return base_content + question_content
    
# Function to send emails
def send_email(to_email, subject, content):
    sg = SendGridAPIClient(SENDGRID_API_KEY)
    email = Mail(from_email=HOST_EMAIL, to_emails=to_email, subject=subject, html_content=content)
    sg.send(email)

    
# Discord Instructions in Markdown format
discord_instructions_markdown = """
### Joining the AI Study Group on Discord
To join the virtual AI Study Group on Discord, please follow these steps:

1. If you don't have Discord, download it from [Discord's official website](https://discord.com/) or install the app on your mobile device.
2. Create a Discord account if you don't have one.
3. Scan the QR code provided or click on the Discord link to join our server.
4. Once in the server, introduce yourself in the introduction channel and feel free to explore different channels.
5. Respect community guidelines and enjoy collaborating with fellow AI enthusiasts!
"""

# GDPR Notice and Consent in Markdown format
gdpr_markdown = """
### Privacy Notice and Consent
By submitting this form, you consent to the processing and storage of your personal data as outlined below:

- **Purpose**: Your data is collected to verify your intention to attend the event and to prevent spam and trolling.
- **Data Storage**: Your personal information is stored securely and will only be used for the purposes of event management.
- **Data Access**: You have the right to access your personal data upon request.
- **Data Deletion**: You can request the deletion of your personal data at any time.
- **No Third Party Sharing**: Your data will not be shared with any third parties.

Please check the box above to indicate your consent.
"""

def calculate_next_event_date():
    today = datetime.date.today()
    first_of_month = datetime.date(today.year, today.month, 1)
    first_sunday = first_of_month + datetime.timedelta(days=(6-first_of_month.weekday()))
    if today <= first_sunday:
        return first_sunday
    else:
        if first_of_month.month == 12:
            return datetime.date(first_of_month.year + 1, 1, 1) + datetime.timedelta(days=(6-1))
        else:
            return datetime.date(first_of_month.year, first_of_month.month + 1, 1) + datetime.timedelta(days=(6-1))

# Main RSVP function
def add_rsvp(name, email, question, consent):
    if not consent or not email:
        return "**Error**: Consent and Email are required to RSVP."
    
    if email in submitted_emails:
        return ["**Error**: You have already submitted an RSVP.", "", ""]

    event_date = calculate_next_event_date().strftime("%B %d, %Y")
    event_time = "2:00 PM to 3:30 PM"
    rsvp_timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Create email content
    attendee_email_content = create_email_content(name, email, question, event_date, event_time, rsvp_timestamp)
    host_email_content = f'''
        <p>New RSVP received for the AI Study Group:</p>
        <p><b>Name:</b> {name}</p>
        <p><b>Email:</b> {email}</p>
        <p><b>RSVP Timestamp:</b> {rsvp_timestamp}</p>
        <p><b>Event Date:</b> {event_date} {event_time}</p>
        {attendee_email_content}
    '''

    # Send emails
    send_email(email, f'Thank you for your RSVP on {event_date} at {event_time}', attendee_email_content)
    send_email(HOST_EMAIL, f'New RSVP to AI Study Group {event_date} received', host_email_content)
    
    # Add the email to the set of submitted emails
    submitted_emails.add(email)
    
    # Return the response, GDPR notice, and Discord instructions
    response = f"**Thank you** for your RSVP, {name}. Please [join the study group on Discord]({DISCORD_LINK})."
    return [response, gdpr_markdown, discord_instructions_markdown]


# Gradio interface with Markdown component for GDPR notice and Discord Instructions
demo = gr.Interface(
    fn=add_rsvp,
    inputs=[
        gr.Textbox(label="Enter your full name"),
        gr.Textbox(label="Enter your email", placeholder="example@example.com", type="email"),
        gr.Textbox(label="What is your question for the study group?", lines=7),
        gr.Checkbox(label="I consent to my data being processed and stored in accordance with the privacy policy.", value=False)
    ],
    outputs=[  
        gr.Markdown(), # Response
        gr.Markdown(), # GDPR Notice
        gr.Markdown()
    ],
    title="AI Study Group RSVP",
    description="Please fill in your details to RSVP for the study group.",
    article=gdpr_markdown + discord_instructions_markdown  # Combining GDPR and Discord instructions in the article
)

# Run the Gradio app
demo.launch()