Exemplo n.º 1
0
        content = conn.getresponse()
        data = content.read()
    except socket_error as serr:
        # 101 remote host naughty
        # 104 your router naughty
        if serr.errno not in (101, 104):
            raise serr
        else:
            # reconnect if connection is dropped
            conn.close(),
            conn = httplib.HTTPConnection("reisapi.ruter.no")
    except http_error as herr:
        print(str(herr))
    # Parse returned data into Dictionary object
    jDict = json.loads(data)
    er = jDict['ReisError']
    if er == None:
        # Gets first proposal neares in time
        tt = jDict['TravelProposals'][0]['DepartureTime']
        # Some arithmetic to figure out minutes until departure
        current = datetime.datetime.strptime(currenttime, "%d%m%Y%H%M%S")
        next = datetime.datetime.strptime(tt, "%Y-%m-%dT%H:%M:%S")
        diff = next - current
        diffmin = (diff.days * 24 * 60) + (diff.seconds / 60)
        # Don't need this fancy digit thing but easier to read
        sense.set_pixels(digit.makedigit(diffmin))
    else:
        print(er)
    ## Be nice to the API servers
    time.sleep(10)
Exemplo n.º 2
0
from sense_hat import SenseHat
import digit, time

sense = SenseHat()
sense.clear()
sense.set_rotation(180)

while True:
    hum = int(round(sense.get_humidity(),0))
    sense.set_pixels(digit.makedigit(hum))
    # Check every minute
    time.sleep(60)
Exemplo n.º 3
0
from sense_hat import SenseHat
import digit, time

sense = SenseHat()
sense.clear()
sense.set_rotation(180)

while True:
    temp = int(round(sense.get_temperature(), 0))
    # "Calibrate"
    temp -= 10
    print(temp)
    sense.set_pixels(digit.makedigit(temp))
    # Check every minute
    time.sleep(60)
Exemplo n.º 4
0
		data=content.read()
	except socket_error as serr: 
		# 101 remote host naughty
		# 104 your router naughty
		if serr.errno not in (101, 104):
			raise serr
		else:
			# reconnect if connection is dropped
			conn.close(),
			conn = httplib.HTTPConnection("reisapi.ruter.no")
	except http_error as herr:
		print(str(herr))
	# Parse returned data into Dictionary object
	jDict = json.loads(data)
	er = jDict['ReisError']
	if er==None:
		# Gets first proposal neares in time
		tt = jDict['TravelProposals'][0]['DepartureTime']
		# Some arithmetic to figure out minutes until departure
		current=datetime.datetime.strptime(currenttime,"%d%m%Y%H%M%S")
		next=datetime.datetime.strptime(tt,"%Y-%m-%dT%H:%M:%S")
		diff = next-current
		diffmin = (diff.days * 24 * 60) + (diff.seconds/60)
		# Don't need this fancy digit thing but easier to read
		sense.set_pixels(digit.makedigit(diffmin))
	else:
		print(er)
	## Be nice to the API servers
	time.sleep(10)

Exemplo n.º 5
0
from sense_hat import SenseHat
import digit, time

sense = SenseHat()
sense.clear()
sense.set_rotation(180)

while True:
    temp = int(round(sense.get_temperature(),0))
    # "Calibrate"
    temp -= 10
    print(temp)
    sense.set_pixels(digit.makedigit(temp))
    # Check every minute
    time.sleep(60)