Exemplo n.º 1
0
def query():
    feedback_file = './image_feedback/'
    feedback_file_name = os.listdir(feedback_file)[0]
    #replace function to remove the word jpg
    if request.method == 'GET':
        return render_template("feedback.html")
    classification = format(request.form['classification'])
    reason = format(request.form['reason'])
    mail = format(request.form['email'])
    feedback_folder = './image_feedback/'
    feedback_file = os.listdir(feedback_folder)[0]
    feedback_file_full = './image_feedback/' + feedback_file
    with open(feedback_file_full, 'rb') as f:
        data = f.read()
    encoded = base64.b64encode(data).decode()
    attachment = Attachment()
    attachment.content = encoded
    attachment.type = "application/jpg"
    if attachment.type != "application/jpg":  #allows only png and jpg
        attachment.type = "application/png"
        attachment.type = "application/png"
    attachment.filename = feedback_file_name
    attachment.disposition = "attachment"
    attachment.content_id = "image file"
    from_email = Email("*****@*****.**")
    sg = sendgrid.SendGridAPIClient(
        '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'
    )
    subject = "Concrete Surface misclassification query"
    to_email = Email(mail)
    cc_email = Email("*****@*****.**")
    p = Personalization()
    p.add_to(to_email)
    p.add_cc(cc_email)
    message = "your query:" + "" + classification + " " + reason + ". " + "This is the query receipt. The incorrectly classified image is attached to the email "
    #print(message)
    content = Content("text/plain", message)
    mail = Mail(from_email, subject, to_email, content)
    mail.add_personalization(p)  # allows you to send  CC = carbon copy
    mail.add_attachment(attachment)
    response = sg.client.mail.send.post(request_body=mail.get())
    print(response.status_code)
    print(response.body)
    print(response.headers)
    return render_template("finished_feedback.html")
Exemplo n.º 2
0
def send():
    datetime.datetime.now()
    time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    result_file = './image_email/'
    result_file_name = os.listdir(result_file)[0]
    result_file_name_no_ext = (os.path.splitext(result_file_name)[0])
    #replace function to remove the word jpg
    if request.method == 'GET':  # if someone presses on that send button it renders the email template
        return render_template("send_email.html")
        #return'<form action="send" method = "POST"><input name ="email"><input type ="submit"></form>'
        #code above was used to test if email could be sent
    mail = format(request.form['email'])
    location = format(request.form['location'])
    email_folder = './image_email/'
    files = os.listdir(email_folder)[0]
    image_file = './image_email/' + files
    with open(image_file, 'rb') as f:
        data = f.read()
    encoded = base64.b64encode(data).decode()
    attachment = Attachment()
    #attachment.set_content(encoded) # there was no documentation to handle this problem figure this out by.
    attachment.content = encoded
    attachment.type = "application/jpg"
    if attachment.type != "application/jpg":  #allows only png and jpg
        attachment.type = "application/png"
        attachment.type = "application/png"
    attachment.filename = result_file_name
    attachment.disposition = "attachment"
    attachment.content_id = "image file"
    from_email = Email("*****@*****.**")
    sg = sendgrid.SendGridAPIClient(
        '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'
    )
    subject = "Concrete Surface Results"
    to_email = Email(mail)
    message = "this is the results" + " " + result_file_name_no_ext + " " + "for building in:" + location + ". " + "Concrete surface found at:" + time + ". " + "The attachment has been named to the classification results"
    content = Content("text/plain", message)
    mail = Mail(from_email, subject, to_email, content)
    mail.add_attachment(attachment)
    response = sg.client.mail.send.post(request_body=mail.get())
    print(response.status_code)
    print(response.body)
    print(response.headers)
    return render_template("finished.html")