コード例 #1
0
ファイル: infoemail.py プロジェクト: gruen/piweb.site
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
ファイル: gatherdata.py プロジェクト: lakehousepi/piweb.site
def gatherdata():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    # Get IP data, snap timestamp, insert data
    ipaddrs = both_ip()
    timestamp = datetime.datetime.now()

    global_ips = IPSeries.objects.get(name='Global')
    local_ips = IPSeries.objects.get(name='Local')

    global_ipr = IPReading(ipseries=global_ips,
                           value=ipaddrs['global_ip'],
                           timestamp=timestamp)
    global_ipr.save()

    local_ipr = IPReading(ipseries=local_ips,
                          value=ipaddrs['local_ip'],
                          timestamp=timestamp)
    local_ipr.save()

    # Get temp data, snap timestamp, insert data
    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    timestamp = datetime.datetime.now()

    upstairs_ts = TempSeries.objects.get(name='Upstairs')
    upstairs_tr = TempReading(tempseries=upstairs_ts,
                              value=temp['temp_f'],
                              scale='F',
                              timestamp=timestamp)
    upstairs_tr.save()

    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
ファイル: gatherdata.py プロジェクト: gruen/piweb.site
def gatherdata():
    green = LEDController(led_pin=pins.GREEN_LED)
    green.on()

    # Get IP data, snap timestamp, insert data
    ipaddrs = both_ip()
    timestamp = datetime.datetime.now()

    global_ips = IPSeries.objects.get(name='Global')
    local_ips = IPSeries.objects.get(name='Local')

    global_ipr = IPReading(
        ipseries=global_ips,
        value=ipaddrs['global_ip'],
        timestamp=timestamp
    )
    global_ipr.save()

    local_ipr = IPReading(
        ipseries=local_ips,
        value=ipaddrs['local_ip'],
        timestamp=timestamp
    )
    local_ipr.save()

    # Get temp data, snap timestamp, insert data
    tr = TempReader(temp_sensor_pin=pins.TEMP_SENSOR)
    temp = tr.read_temp()
    timestamp = datetime.datetime.now()

    upstairs_ts = TempSeries.objects.get(name='Upstairs')
    upstairs_tr = TempReading(
        tempseries=upstairs_ts,
        value=temp['temp_f'],
        scale='F',
        timestamp=timestamp
    )
    upstairs_tr.save()

    green.off()
コード例 #5
0
ファイル: infoemail.py プロジェクト: gruen/piweb.site
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()
コード例 #6
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()
コード例 #7
0
ファイル: gdocupdate.py プロジェクト: gruen/piweb.site
def gdocupdate():
    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['tempfahrenheit'] = str(temp['temp_f'])

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

    gsu = GSpreadsheetUpdater(gdocs.USERNAME, gdocs.PASSWORD, None, gdocs.SPREADSHEETKEY, gdocs.WORKSHEETID)
    gsu.login()
    gsu.insertrow(datadict)
    
    green.off()