Пример #1
0
# Declare variables
from_addr = "EMAIL ADDRESS"
to_addr = "EMAIL ADDRESS"
server = 'smtp.gmail.com'
server_port = 587
email_pwd = "FROM EMAIL PASSWORD" # TODO: Move this to config.py module

email_subj = "Advising Signup Cancellation"
email_body = ("Advising Signup with McGrath, D Kevin CANCELLED\n"
              "Name: REDACTED\n"
              "Email: [email protected]\n"
              "Date: Wednesday, November 21st, 2012\n"
              "Time: 1:00pm - 1:15pm\n"
             )
appointment_id = "324"
start_dtim = "20160316T153000Z"
end_dtim = "20160316T160000Z"
student_email = "*****@*****.**"

# Create CalAppt object

test1 = CalAppt(from_addr, to_addr, server, server_port, email_pwd)

# Send Calendar appt

test1.sendCncl(email_subj, email_body, appointment_id, start_dtim, end_dtim, student_email)

# Print confirmation

print "Email sucesfully sent."
Пример #2
0
def delete_appt(max_y, max_x, menu_items, choice):

    # Change to true if this function does everything it needs to do
    success = False

    # Open the database
    con = db_connect()

    # Parse start and end datetime structs from the date strings
    ts = time.strptime(str(menu_items[choice][1]), '%Y-%m-%d %H:%M:%S')
    te = time.strptime(str(menu_items[choice][2]), '%Y-%m-%d %H:%M:%S')

    # Make start and end datetime objects from datetime struct data
    appt_sdt = datetime.datetime(ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec)
    appt_edt = datetime.datetime(te.tm_year, te.tm_mon, te.tm_mday, te.tm_hour, te.tm_min, te.tm_sec)

    # Build ISO date strings (used by iCalendar) from datetime struct
    # data. Format: YYYYMMDDTHHMMSSZ
    iso_start = str(ts.tm_year) + str(ts.tm_mon) + str(ts.tm_mday) + "T" + \
                str(ts.tm_hour) + str(ts.tm_min) + str(ts.tm_sec) + "Z"
    iso_end   = str(te.tm_year) + str(te.tm_mon) + str(te.tm_mday) + "T" + \
                str(te.tm_hour) + str(te.tm_min) + str(te.tm_sec) + "Z"

    # Build appointment date and start/end time strings from datetime objects
    appt_date  = appt_sdt.strftime("%A, %B %-d, %Y")
    appt_stime = appt_sdt.strftime("%-I:%M%p")
    appt_etime = appt_edt.strftime("%-I:%M%p")

    # Declare variables
    from_addr = credentials.emailusername
    to_addr = credentials.emailusername
    server = 'smtp.gmail.com'
    server_port = 587
    email_pwd = credentials.emailpassword 
    
    email_subj = "Advising Signup Cancellation"
    email_body = ("Advising Signup CANCELLED\n"
                  "Name: "  + menu_items[choice][3] + "\n"
                  "Email: " + menu_items[choice][4] + "\n"
                  "Date: "  + appt_date + "\n"
                  "Time: "  + appt_stime + " - " + appt_etime
                 )
    appointment_id = str(menu_items[choice][0])
    start_dtim = iso_start
    end_dtim = iso_end
    student_email = menu_items[choice][4]
    
    # Create CalAppt object
    cncl_mail = CalAppt(from_addr, to_addr, server, server_port, email_pwd)
    
    # Send Calendar appt. If no exceptions were encountered during the
    # sending of the email, 'emailed' will be set to True.
    emailed = cncl_mail.sendCncl(email_subj, email_body, appointment_id, start_dtim, end_dtim, student_email)
    
    if emailed:
        # Delete the item from the database
        con.execute("DELETE FROM appointment WHERE id=?", (menu_items[choice][0],))
        con.commit()

        # Make sure one change was made to the database. 
        if con.total_changes == 1:
            success = True

    # Close the database connection
    con.close()

    return success