Modified "Astros" project help needed - Raspberry Pi Forums


hello,
son completed "people in space indicator" project , he'd show off @ upcoming event. issue there no internet available @ event , i'm having hard time figuring out how code work local json file.
here original code had:

code: select all

from time import sleep gpiozero import led import requests pins = [2, 3, 4, 14, 15, 17, 18, 27, 22, 23] leds = [led(p) p in pins] url = "http://api.open-notify.org/astros.json" while true:     r = requests.get(url)     j = r.json()     n = j['number']     astronauts = j['people']     [led.off() led in leds]     print("\n" *10) # clears 10 lines of screen next run     i, led in enumerate(leds):         if n > i:             led.on()             print(astronauts[i]['name'])             print(astronauts[i]['craft'])             sleep(1)         else:             led.off()     sleep(30) # update every 30 seconds
i've got json file local, , i've tried using code...

code: select all

from time import sleep gpiozero import led import json open('/home/pi/astros/astros.json')as json_data:     pins = [2, 3, 4, 14, 15, 17, 18, 27, 22, 23]     leds = [led(p) p in pins]     while true:         #j = json()         n = ['number']         astronauts = ['people']         [led.off() led in leds]         print("\n" *10) # clears 10 lines of screen next run         i, led in enumerate(leds):             if n > i:                 led.on()                 print(astronauts[i]['name'])                 print(astronauts[i]['craft'])                 sleep(1)             else:                 led.off()         sleep(30) # update every 30 seconds
error...

"traceback (most recent call last):
file "/home/pi/astros/astronauts_static_local.py", line 16, in <module>
if n > i:
typeerror: unorderable types: list() > int()"

i'd code close original possible. here?

thanks.

1lovcars wrote: i'd code close original possible. here?
run trivial webserver on same rpi serve astros.json file.

need change url = "http://api.open-notify.org/astros.json" url = "http://localhost/astros.json"

if might work, further details on request. it's not hard...


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code