Skip to content

Commit e541429

Browse files
committed
Fix missing-final-newline and missing-final-newline
1 parent a7d8e99 commit e541429

13 files changed

Lines changed: 337 additions & 337 deletions

File tree

Bluetooth_Room_Lights/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,4 @@ def draw(self): # draw the animation
175175
if MODE == 1:
176176
animations.animate()
177177
if MODE == 4:
178-
animations.freeze()
178+
animations.freeze()

IoT_NeoPixel_Sign/code.py

100755100644
Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
import ssl
2-
import board
3-
import neopixel
4-
import adafruit_requests
5-
import socketpool
6-
import wifi
7-
from adafruit_io.adafruit_io import IO_HTTP
8-
from adafruit_pixel_framebuf import PixelFramebuffer
9-
# adafruit_circuitpython_adafruitio usage with native wifi networking
10-
11-
# Neopixel matrix configuration
12-
PIXEL_PIN = board.IO6
13-
PIXEL_WIDTH = 12
14-
PIXEL_HEIGHT = 12
15-
16-
# secrets.py has SSID/password and adafruit.io
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("WiFi secrets are kept in secrets.py, please add them there!")
21-
raise
22-
AIO_USERNAME = secrets["aio_username"]
23-
AIO_KEY = secrets["aio_key"]
24-
25-
# LED matrix creation
26-
PIXELS = neopixel.NeoPixel(
27-
PIXEL_PIN, PIXEL_WIDTH * PIXEL_HEIGHT, brightness=0.5, auto_write=False,
28-
)
29-
30-
PIXEL_FRAMEBUF = PixelFramebuffer(
31-
PIXELS,
32-
PIXEL_WIDTH,
33-
PIXEL_HEIGHT,
34-
alternating=True,
35-
rotation=1,
36-
reverse_x=True
37-
)
38-
39-
# Adafruit.io feeds setup
40-
QUOTE_FEED = "sign-quotes.signtext"
41-
COLOR_FEED = "sign-quotes.signcolor"
42-
CURRENT_TEXT = "Merry Christmas!"
43-
CURRENT_COLOR = 0xFFFFFF
44-
45-
# Helper function to get updated data from Adafruit.io
46-
def update_data():
47-
global CURRENT_TEXT, CURRENT_COLOR
48-
print("Updating data from Adafruit IO")
49-
try:
50-
quote_feed = IO.get_feed(QUOTE_FEED)
51-
quotes_data = IO.receive_data(quote_feed["key"])
52-
CURRENT_TEXT = quotes_data["value"]
53-
color_feed = IO.get_feed(COLOR_FEED)
54-
color_data = IO.receive_data(color_feed["key"])
55-
CURRENT_COLOR = int(color_data["value"][1:], 16)
56-
# pylint: disable=broad-except
57-
except Exception as error:
58-
print(error)
59-
60-
61-
# Connect to WiFi
62-
print("Connecting to %s" % secrets["ssid"])
63-
wifi.radio.connect(secrets["ssid"], secrets["password"])
64-
print("Connected to %s!" % secrets["ssid"])
65-
66-
# Setup Adafruit IO connection
67-
POOL = socketpool.SocketPool(wifi.radio)
68-
REQUESTS = adafruit_requests.Session(POOL, ssl.create_default_context())
69-
# Initialize an Adafruit IO HTTP API object
70-
IO = IO_HTTP(AIO_USERNAME, AIO_KEY, REQUESTS)
71-
72-
73-
while True:
74-
update_data()
75-
print("Displaying", CURRENT_TEXT, "in", hex(CURRENT_COLOR))
76-
77-
for i in range(12 * len(CURRENT_TEXT) + PIXEL_WIDTH):
78-
PIXEL_FRAMEBUF.fill(0x000000)
79-
PIXEL_FRAMEBUF.pixel(0, 0, 0x000000)
80-
PIXEL_FRAMEBUF.text(CURRENT_TEXT, PIXEL_WIDTH - i, 3, CURRENT_COLOR)
81-
PIXEL_FRAMEBUF.display()
1+
import ssl
2+
import board
3+
import neopixel
4+
import adafruit_requests
5+
import socketpool
6+
import wifi
7+
from adafruit_io.adafruit_io import IO_HTTP
8+
from adafruit_pixel_framebuf import PixelFramebuffer
9+
# adafruit_circuitpython_adafruitio usage with native wifi networking
10+
11+
# Neopixel matrix configuration
12+
PIXEL_PIN = board.IO6
13+
PIXEL_WIDTH = 12
14+
PIXEL_HEIGHT = 12
15+
16+
# secrets.py has SSID/password and adafruit.io
17+
try:
18+
from secrets import secrets
19+
except ImportError:
20+
print("WiFi secrets are kept in secrets.py, please add them there!")
21+
raise
22+
AIO_USERNAME = secrets["aio_username"]
23+
AIO_KEY = secrets["aio_key"]
24+
25+
# LED matrix creation
26+
PIXELS = neopixel.NeoPixel(
27+
PIXEL_PIN, PIXEL_WIDTH * PIXEL_HEIGHT, brightness=0.5, auto_write=False,
28+
)
29+
30+
PIXEL_FRAMEBUF = PixelFramebuffer(
31+
PIXELS,
32+
PIXEL_WIDTH,
33+
PIXEL_HEIGHT,
34+
alternating=True,
35+
rotation=1,
36+
reverse_x=True
37+
)
38+
39+
# Adafruit.io feeds setup
40+
QUOTE_FEED = "sign-quotes.signtext"
41+
COLOR_FEED = "sign-quotes.signcolor"
42+
CURRENT_TEXT = "Merry Christmas!"
43+
CURRENT_COLOR = 0xFFFFFF
44+
45+
# Helper function to get updated data from Adafruit.io
46+
def update_data():
47+
global CURRENT_TEXT, CURRENT_COLOR
48+
print("Updating data from Adafruit IO")
49+
try:
50+
quote_feed = IO.get_feed(QUOTE_FEED)
51+
quotes_data = IO.receive_data(quote_feed["key"])
52+
CURRENT_TEXT = quotes_data["value"]
53+
color_feed = IO.get_feed(COLOR_FEED)
54+
color_data = IO.receive_data(color_feed["key"])
55+
CURRENT_COLOR = int(color_data["value"][1:], 16)
56+
# pylint: disable=broad-except
57+
except Exception as error:
58+
print(error)
59+
60+
61+
# Connect to WiFi
62+
print("Connecting to %s" % secrets["ssid"])
63+
wifi.radio.connect(secrets["ssid"], secrets["password"])
64+
print("Connected to %s!" % secrets["ssid"])
65+
66+
# Setup Adafruit IO connection
67+
POOL = socketpool.SocketPool(wifi.radio)
68+
REQUESTS = adafruit_requests.Session(POOL, ssl.create_default_context())
69+
# Initialize an Adafruit IO HTTP API object
70+
IO = IO_HTTP(AIO_USERNAME, AIO_KEY, REQUESTS)
71+
72+
73+
while True:
74+
update_data()
75+
print("Displaying", CURRENT_TEXT, "in", hex(CURRENT_COLOR))
76+
77+
for i in range(12 * len(CURRENT_TEXT) + PIXEL_WIDTH):
78+
PIXEL_FRAMEBUF.fill(0x000000)
79+
PIXEL_FRAMEBUF.pixel(0, 0, 0x000000)
80+
PIXEL_FRAMEBUF.text(CURRENT_TEXT, PIXEL_WIDTH - i, 3, CURRENT_COLOR)
81+
PIXEL_FRAMEBUF.display()

MagTag_NextBus/nextbus.py

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
"""
2-
NextBus class -- handles NextBus server queries and infers
3-
arrival times based on last-queried predictions and elapsed time.
4-
"""
5-
6-
# pylint: disable=bare-except, too-many-instance-attributes, too-many-arguments
7-
8-
import re
9-
import time
10-
11-
class NextBus():
12-
""" Class to handle NextBus prediction times for one route & stop.
13-
"""
14-
15-
def __init__(self, network, agency, route, stop, data=None,
16-
max_predictions=3, minimum_time=300):
17-
""" Constructor expects a Requests-capable Network object,
18-
strings for transit agency, route, and stop ID, plus optional
19-
per-stop data as defined by an application (e.g. text
20-
description, but could be an object or tuple of data, or None,
21-
or whatever's needed by the app), limits for the maximum number
22-
of future arrivals to predict (limited to server response,
23-
typically 5) and minimum time below which arrivals are not shown
24-
(to discourage unsafe bus-chasing).
25-
"""
26-
self.network = network
27-
self.agency = agency
28-
self.route = route
29-
self.stop = stop
30-
self.data = data
31-
self.max_predictions = max_predictions
32-
self.minimum_time = minimum_time
33-
self.predictions = []
34-
self.last_query_time = -1000
35-
36-
def fetch(self):
37-
""" Contact NextBus server and request predictions for one
38-
agency/route/stop.
39-
"""
40-
try:
41-
url = ('http://webservices.nextbus.com/service/publicXMLFeed?' +
42-
'command=predictions&a=' + self.agency +
43-
'&r=' + self.route + '&s=' + self.stop)
44-
response = self.network.requests.get(url)
45-
if response.status_code == 200:
46-
string = response.text
47-
self.last_query_time = time.monotonic()
48-
self.predictions = []
49-
while len(self.predictions) < self.max_predictions:
50-
# CircuitPython version of re library doesn't have findall.
51-
# Search for first instance of seconds="N" string and then
52-
# increment the string position based on match length.
53-
match = re.search('seconds=\"[0-9]*', string)
54-
if match:
55-
seconds = int(match.group(0)[9:]) # Remove 'seconds="'
56-
if seconds >= self.minimum_time:
57-
self.predictions.append(seconds)
58-
string = string[match.end():]
59-
else:
60-
break
61-
self.predictions.sort()
62-
except:
63-
# If server query fails, we can keep extrapolating from the
64-
# last set of predictions and try query again on next pass.
65-
pass
66-
67-
def predict(self):
68-
""" Extrapolate predictions based on last values queried from
69-
NextBus server and time elapsed since last query. Predictions
70-
are returned as a list of integer seconds values.
71-
"""
72-
times = []
73-
for predict in self.predictions:
74-
seconds = predict - (time.monotonic() - self.last_query_time)
75-
if seconds >= self.minimum_time:
76-
times.append(seconds)
77-
return times
1+
"""
2+
NextBus class -- handles NextBus server queries and infers
3+
arrival times based on last-queried predictions and elapsed time.
4+
"""
5+
6+
# pylint: disable=bare-except, too-many-instance-attributes, too-many-arguments
7+
8+
import re
9+
import time
10+
11+
class NextBus():
12+
""" Class to handle NextBus prediction times for one route & stop.
13+
"""
14+
15+
def __init__(self, network, agency, route, stop, data=None,
16+
max_predictions=3, minimum_time=300):
17+
""" Constructor expects a Requests-capable Network object,
18+
strings for transit agency, route, and stop ID, plus optional
19+
per-stop data as defined by an application (e.g. text
20+
description, but could be an object or tuple of data, or None,
21+
or whatever's needed by the app), limits for the maximum number
22+
of future arrivals to predict (limited to server response,
23+
typically 5) and minimum time below which arrivals are not shown
24+
(to discourage unsafe bus-chasing).
25+
"""
26+
self.network = network
27+
self.agency = agency
28+
self.route = route
29+
self.stop = stop
30+
self.data = data
31+
self.max_predictions = max_predictions
32+
self.minimum_time = minimum_time
33+
self.predictions = []
34+
self.last_query_time = -1000
35+
36+
def fetch(self):
37+
""" Contact NextBus server and request predictions for one
38+
agency/route/stop.
39+
"""
40+
try:
41+
url = ('http://webservices.nextbus.com/service/publicXMLFeed?' +
42+
'command=predictions&a=' + self.agency +
43+
'&r=' + self.route + '&s=' + self.stop)
44+
response = self.network.requests.get(url)
45+
if response.status_code == 200:
46+
string = response.text
47+
self.last_query_time = time.monotonic()
48+
self.predictions = []
49+
while len(self.predictions) < self.max_predictions:
50+
# CircuitPython version of re library doesn't have findall.
51+
# Search for first instance of seconds="N" string and then
52+
# increment the string position based on match length.
53+
match = re.search('seconds=\"[0-9]*', string)
54+
if match:
55+
seconds = int(match.group(0)[9:]) # Remove 'seconds="'
56+
if seconds >= self.minimum_time:
57+
self.predictions.append(seconds)
58+
string = string[match.end():]
59+
else:
60+
break
61+
self.predictions.sort()
62+
except:
63+
# If server query fails, we can keep extrapolating from the
64+
# last set of predictions and try query again on next pass.
65+
pass
66+
67+
def predict(self):
68+
""" Extrapolate predictions based on last values queried from
69+
NextBus server and time elapsed since last query. Predictions
70+
are returned as a list of integer seconds values.
71+
"""
72+
times = []
73+
for predict in self.predictions:
74+
seconds = predict - (time.monotonic() - self.last_query_time)
75+
if seconds >= self.minimum_time:
76+
times.append(seconds)
77+
return times

0 commit comments

Comments
 (0)