Skip to content

Commit 51b97d1

Browse files
committed
Linted
1 parent 46e0936 commit 51b97d1

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

Magic_AI_Storybook/listener.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def __init__(self, api_key, energy_threshold=300, record_timeout=30):
1414
self.recognizer = sr.Recognizer()
1515
self.recognizer.energy_threshold = energy_threshold
1616
with self.microphone as source:
17-
self.recognizer.adjust_for_ambient_noise(source) # we only need to calibrate once, before we start listening
17+
self.recognizer.adjust_for_ambient_noise(
18+
source
19+
) # we only need to calibrate once, before we start listening
1820
self.record_timeout = record_timeout
1921
self.listener_handle = None
2022
self.audio = None
@@ -24,18 +26,17 @@ def listen(self, ready_callback=None):
2426
self._start_listening()
2527
if ready_callback:
2628
ready_callback()
27-
while (
28-
self.listener_handle
29-
and self.audio is None
30-
):
29+
while self.listener_handle and self.audio is None:
3130
time.sleep(0.1)
3231
self.stop_listening()
3332

3433
def _save_audio_callback(self, _recognizer, audio):
3534
self.audio = audio
3635

3736
def _start_listening(self):
38-
self.listener_handle = self.recognizer.listen_in_background(self.microphone, self._save_audio_callback)
37+
self.listener_handle = self.recognizer.listen_in_background(
38+
self.microphone, self._save_audio_callback
39+
)
3940

4041
def stop_listening(self, wait_for_stop=False):
4142
if self.listener_handle:
@@ -60,9 +61,9 @@ def recognize(self):
6061
)
6162

6263
return result.strip()
63-
except sr.RequestError as e:
64+
except sr.RequestError:
6465
time.sleep(3)
6566
attempts += 1
6667
print("I wasn't able to understand you. Please repeat that.")
6768
return None
68-
return None
69+
return None

Magic_AI_Storybook/make_shortcut.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
44
#
55
# SPDX-License-Identifier: MIT
6-
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
6+
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book"
7+
# title="book icons">Book icons created by Freepik - Flaticon</a>
78

89
import os
910

11+
1012
def create_folders(file_path):
1113
path = os.path.dirname(file_path)
1214
if not os.path.exists(path):
1315
os.makedirs(path)
1416

17+
1518
def write_file(path, contents):
1619
create_folders(path)
1720
with open(path, "w") as f:
1821
f.write(contents)
1922

2023
print(f"Shortcut created at {path}")
2124

25+
2226
def main():
2327
APP_TITLE = "Magic Storybook"
2428
RUN_IN_TERMINAL = True
@@ -40,17 +44,18 @@ def main():
4044
APP_ICON = APP_ICON.replace("~", user_homedir)
4145

4246
shortcut_template = f"""[Desktop Entry]
43-
Comment=Run {APP_TITLE}
44-
Terminal={"true" if RUN_IN_TERMINAL else "false"}
45-
Name={APP_TITLE}
46-
Exec=sudo python {APP_PATH}
47-
Type=Application
48-
Icon={APP_ICON}
49-
"""
47+
Comment=Run {APP_TITLE}
48+
Terminal={"true" if RUN_IN_TERMINAL else "false"}
49+
Name={APP_TITLE}
50+
Exec=sudo python {APP_PATH}
51+
Type=Application
52+
Icon={APP_ICON}
53+
"""
5054

5155
write_file(f"{user_homedir}/Desktop/{FILENAME}", shortcut_template)
5256
if AUTO_START:
5357
write_file(f"{user_homedir}/.config/autostart/{FILENAME}", shortcut_template)
5458

59+
5560
if __name__ == "__main__":
56-
main()
61+
main()

Magic_AI_Storybook/story.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131

3232
# Quit Settings (Close book QUIT_CLOSES within QUIT_TIME_PERIOD to quit)
3333
QUIT_CLOSES = 3
34-
QUIT_TIME_PERIOD = 5 # Time period in Seconds
34+
QUIT_TIME_PERIOD = 5 # Time period in Seconds
3535

3636
# Neopixel Settings
3737
NEOPIXEL_COUNT = 10
3838
NEOPIXEL_BRIGHTNESS = 0.2
3939
NEOPIXEL_ORDER = neopixel.GRBW
40-
NEOPIXEL_LOADING_COLOR = (0, 255, 0, 0) # Loading/Dreaming (Green)
41-
NEOPIXEL_SLEEP_COLOR = (0, 0, 0, 0) # Sleeping (Off)
42-
NEOPIXEL_WAITING_COLOR = (255, 255, 0, 0) # Waiting for Input (Yellow)
43-
NEOPIXEL_READING_COLOR = (0, 0, 255, 0) # Reading (Blue)
40+
NEOPIXEL_LOADING_COLOR = (0, 255, 0, 0) # Loading/Dreaming (Green)
41+
NEOPIXEL_SLEEP_COLOR = (0, 0, 0, 0) # Sleeping (Off)
42+
NEOPIXEL_WAITING_COLOR = (255, 255, 0, 0) # Waiting for Input (Yellow)
43+
NEOPIXEL_READING_COLOR = (0, 0, 255, 0) # Reading (Blue)
4444
NEOPIXEL_PULSE_SPEED = 0.1
4545

4646
# Image Names
@@ -116,11 +116,13 @@
116116
print("Please make sure PROMPT_FILE points to a valid file.")
117117
sys.exit(1)
118118

119+
119120
def strip_fancy_quotes(text):
120121
text = re.sub(r"[\u2018\u2019]", "'", text)
121122
text = re.sub(r"[\u201C\u201D]", '"', text)
122123
return text
123124

125+
124126
class Position(Enum):
125127
TOP = 0
126128
CENTER = 1
@@ -237,7 +239,7 @@ def start(self):
237239
with open(PROMPT_FILE, "r") as f:
238240
self._prompt = f.read()
239241

240-
#Initialize the Listener
242+
# Initialize the Listener
241243
self.listener = Listener(openai.api_key, ENERGY_THRESHOLD, RECORD_TIMEOUT)
242244

243245
# Preload remaining images
@@ -348,7 +350,12 @@ def _handle_loading_status(self):
348350
self.pixels.show()
349351

350352
def _set_status_color(self, status_color):
351-
if status_color not in [NEOPIXEL_READING_COLOR, NEOPIXEL_WAITING_COLOR, NEOPIXEL_SLEEP_COLOR, NEOPIXEL_LOADING_COLOR]:
353+
if status_color not in [
354+
NEOPIXEL_READING_COLOR,
355+
NEOPIXEL_WAITING_COLOR,
356+
NEOPIXEL_SLEEP_COLOR,
357+
NEOPIXEL_LOADING_COLOR,
358+
]:
352359
raise ValueError(f"Invalid status color {status_color}.")
353360

354361
# Handle loading color by setting the loading flag
@@ -713,6 +720,7 @@ def _sendchat(self, prompt):
713720
def running(self):
714721
return self._running
715722

723+
716724
def parse_args():
717725
parser = argparse.ArgumentParser()
718726
# Book will only be rendered vertically for the sake of simplicity

0 commit comments

Comments
 (0)