Exemplo n.º 1
0
        def job():
            weather_dict, icon = get_weather_data('KLAX')
            weather_dict_ordered = OrderedDict(sorted(weather_dict.items()))

            email_file = "Email_File.html"
            create_html_report(weather_dict_ordered, icon, email_file)
            send_gmail(email_file)
Exemplo n.º 2
0
def job():
    pprint(schedule.jobs)
    weather_dict, icon = get_weather_data('KLAX')
    print(weather_dict.items())
    print(sorted(weather_dict.items()))
    weather_dict_ordered = OrderedDict(sorted(weather_dict.items()))
    print(weather_dict_ordered)

    email_file = 'Email_File.html'
    create_html_report(weather_dict, icon, email_file)
    send_gmail(email_file)
def job():
    """Function that will be called based on the scheduled frequency"""
    pprint(schedule.jobs)
    weather_dict, icon = get_weather_data(
        'KNYC'
    )  #default station is KNYC, can be changed to any valid station code
    weather_dict_ordered = OrderedDict(sorted(weather_dict.items(
    )))  #dictionary must be ordered to align with our HTML template

    email_file = "Email_File.html"
    create_html_report(weather_dict_ordered, icon, email_file)
    send_gmail(email_file)
Exemplo n.º 4
0
def send_gmail(msg_file):
    with open(msg_file,
              mode='rb') as message:  # Open report html file for reading
        msg = MIMEText(message.read(), 'html', 'html')  # Create html message

    msg['Subject'] = 'Hourly Weather {}'.format(
        datetime.now().strftime("%Y-%m-%d %H:%M"))
    msg['From'] = '*****@*****.**'
    msg['To'] = '*****@*****.**'  # NO list!

    server = smtplib.SMTP('smtp.gmail.com', port=587)
    server.ehlo()  # Extended Hello
    server.starttls(
    )  # Put the SMTP connection in TLS (Transport Layer Security) mode.
    server.ehlo()  # All SMTP commands that follow will be encrypted.
    server.login('*****@*****.**', GMAIL_PWD)
    server.send_message(msg)
    server.close()


# ===========================================
if __name__ == '__main__':
    from Get_Weather_Data import get_weather_data
    from Create_Html_file import create_html_report

    weather_dict, icon = get_weather_data('KLAX')
    email_file = "Test_Email_File.html"
    create_html_report(weather_dict, icon, email_file)
    send_gmail(email_file)