колба - отправка электронной почты при определенных условиях - PullRequest
0 голосов
/ 06 октября 2018

У меня есть этот скрипт, который отправляет электронное письмо, когда оно удовлетворяет условию.Что не так с кодировкой?Я пытался перезапустить службу несколько раз, но все равно ничего не получилось.

Спасибо за помощь.

from flask import Flask, render_template
from flask_mail import Mail, Message
#other imports


app = Flask(__name__)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'mail@gmail.com'  # enter your email here
app.config['MAIL_DEFAULT_SENDER'] = 'mail@gmail.com' # enter your email here
app.config['MAIL_PASSWORD'] = 'password' # enter your password here
mail=Mail(app)
#other parts unnecessary to be posted

@app.route("/")
def tempReading():
    t=open(temp_sensor,'r')
    lines=t.readlines()
    t.close()

    dista=subprocess.check_output('sudo python /home/pi/webserver/sonic.py', shell=True)

    temp_output = lines[1].find('t=')
    if temp_output != -1:
        temp_string=lines[1].strip()[temp_output+2:]
        temp_c=float(temp_string)/1000.0
    elif temp_c>30:
        msg=Message("Temperature Warning", recipients['1234567@sms.clicksend.com'])
        msg.body="Temperature is ",temp_c
        mail.send(msg)
    templateData = {
        'temp': round(temp_c,1),
                'dis': dista
    }
    return render_template('temp.html',**templateData)


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, debug=True)

1 Ответ

0 голосов
/ 06 октября 2018

Я думаю, вы просто хотите, чтобы это было if, а не elif

temp_c = None
if temp_output != -1:
    temp_string=lines[1].strip()[temp_output+2:]
    temp_c=float(temp_string)/1000.0
else:
    # return an error here if you can't find temp_c?
if temp_c and temp_c>30:
    msg=Message("Temperature Warning", recipients['1234567@sms.clicksend.com'])
    msg.body="Temperature is %d" % temp_c
    mail.send(msg)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...