예제 #1
0
def infoemail():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    datadict = {}

    timestamp = datetime.datetime.now()
    datadict['date'] = timestamp.strftime('%m/%d/%Y')
    datadict['time'] = timestamp.strftime('%H:%M:%S')

    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    datadict['tempcentigrade'] = str(temp['temp_c'])
    datadict['tempfarenheit'] = str(temp['temp_f'])

    ipaddrs = both_ip()
    datadict['localip'] = ipaddrs['local_ip']
    datadict['globalip'] = ipaddrs['global_ip']

    datastring = json.dumps(datadict, indent=4)

    infogroup = Group.objects.get(name='Daily Email')
    infousers = infogroup.user_set.all()

    infoemaillist = []
    for u in infousers:
        infoemaillist.append(u.email)

    es = EmailSender(servername=gdocs.SERVERNAME, username=gdocs.USERNAME,
            password=gdocs.PASSWORD)
    es.sendmail(fromaddr=gdocs.USERNAME, toaddrs=infoemaillist,
            subject='Temperature update', body=datastring)

    green.off()
예제 #2
0
def infoemail_html_with_image():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    datadict = {}

    timestamp = datetime.datetime.now()
    datadict['date'] = timestamp.strftime('%m/%d/%Y')
    datadict['time'] = timestamp.strftime('%H:%M:%S')

    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    datadict['tempcentigrade'] = str(temp['temp_c'])
    datadict['tempfarenheit'] = str(temp['temp_f'])

    ipaddrs = both_ip()
    datadict['localip'] = ipaddrs['local_ip']
    datadict['globalip'] = ipaddrs['global_ip']

    datastring = json.dumps(datadict, indent=4)

    infogroup = Group.objects.get(name='Daily Email')
    infousers = infogroup.user_set.all()

    infoemaillist = []
    for u in infousers:
        infoemaillist.append(u.email)

    t = loader.get_template('utils/email.html')
    c = Context({'dd': datadict})
    h = t.render(c)

    es = EmailSender(servername=gdocs.SERVERNAME,
                     username=gdocs.USERNAME,
                     password=gdocs.PASSWORD)
    es.sendmail_html_with_image(fromaddr=gdocs.USERNAME,
                                toaddrs=infoemaillist,
                                subject='Temperature update (html)',
                                textbody=datastring,
                                htmlbody=h,
                                imagepath=os.path.join(settings.STATIC_ROOT,
                                                       'images',
                                                       'fourgraphs.png'))

    green.off()
예제 #3
0
def infoemail_html_with_image():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    datadict = {}

    timestamp = datetime.datetime.now()
    datadict['date'] = timestamp.strftime('%m/%d/%Y')
    datadict['time'] = timestamp.strftime('%H:%M:%S')

    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    datadict['tempcentigrade'] = str(temp['temp_c'])
    datadict['tempfarenheit'] = str(temp['temp_f'])

    ipaddrs = both_ip()
    datadict['localip'] = ipaddrs['local_ip']
    datadict['globalip'] = ipaddrs['global_ip']

    datastring = json.dumps(datadict, indent=4)

    infogroup = Group.objects.get(name='Daily Email')
    infousers = infogroup.user_set.all()

    infoemaillist = []
    for u in infousers:
        infoemaillist.append(u.email)

    t = loader.get_template('utils/email.html')
    c = Context({'dd': datadict})
    h = t.render(c)

    es = EmailSender(servername=gdocs.SERVERNAME, username=gdocs.USERNAME,
            password=gdocs.PASSWORD)
    es.sendmail_html_with_image(fromaddr=gdocs.USERNAME, toaddrs=infoemaillist,
            subject='Temperature update (html)', textbody=datastring,
            htmlbody=h, imagepath=os.path.join(settings.STATIC_ROOT, 'images', 'fourgraphs.png'))

    green.off()
예제 #4
0
def infoemail():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    datadict = {}

    timestamp = datetime.datetime.now()
    datadict['date'] = timestamp.strftime('%m/%d/%Y')
    datadict['time'] = timestamp.strftime('%H:%M:%S')

    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    datadict['tempcentigrade'] = str(temp['temp_c'])
    datadict['tempfarenheit'] = str(temp['temp_f'])

    ipaddrs = both_ip()
    datadict['localip'] = ipaddrs['local_ip']
    datadict['globalip'] = ipaddrs['global_ip']

    datastring = json.dumps(datadict, indent=4)

    infogroup = Group.objects.get(name='Daily Email')
    infousers = infogroup.user_set.all()

    infoemaillist = []
    for u in infousers:
        infoemaillist.append(u.email)

    es = EmailSender(servername=gdocs.SERVERNAME,
                     username=gdocs.USERNAME,
                     password=gdocs.PASSWORD)
    es.sendmail(fromaddr=gdocs.USERNAME,
                toaddrs=infoemaillist,
                subject='Temperature update',
                body=datastring)

    green.off()