Skip to content

Commit

Permalink
Instead of a beep, use the pyttsx3 library to speak a message when an…
Browse files Browse the repository at this point in the history
… arg player is online.
  • Loading branch information
johndoknjas committed May 27, 2024
1 parent 43cda05 commit 6a7bac8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest lintception requests rich deepdiff mplcursors
pip install flake8 pytest lintception requests rich deepdiff mplcursors pyttsx3
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ To install, run the following command:

`pip install hypickle`

Besides installing the script, this will also automatically install its dependencies (the libraries `requests`,
`rich`, `mplcursors`, `deepdiff`, and any of their own dependencies).
Besides installing the script, this will also automatically install its dependencies (the libraries `requests`, `rich`, `mplcursors`, `deepdiff`, `pyttsx3`, and any of their own dependencies).

Then, create a new folder that will be used to store persistent information (such as friends lists you create).
In this folder, make a textfile called 'api-key.txt', and paste your hypixel api key as the first line.
Expand Down
2 changes: 1 addition & 1 deletion hypickle/Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def iterate_over_friends_for_report(
for player in self._players_used_to_combine:
online_status = 'online' if player.hypixel_object().isOnline((True,)*3) else 'offline'
if online_status == 'online':
print('\a')
Utils.speak(f"{player.name()} is online")
player.print_dict_report(player.get_stats_dict(), f"this arg player is {online_status}")
print()

Expand Down
15 changes: 14 additions & 1 deletion hypickle/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import math
from pprint import pprint
import itertools
import pyttsx3 # type: ignore
talker: Optional[pyttsx3.Engine | Any] = None

def list_subtract(main_list: list, subtract_elems: Iterable) -> list:
subtract_set = set(subtract_elems)
Expand Down Expand Up @@ -271,4 +273,15 @@ def print_diff_dicts(old_dict: dict, new_dict: dict, prepended_msg: str = '') ->
def content_in_file(filename: str) -> bool:
"""Returns True if there is at least one non-whitespace character in the file."""
with open(filename, 'r') as f:
return f.read().strip() != ''
return f.read().strip() != ''

def speak(text: str) -> None:
"""Uses pyttsx3 to do text to speech."""
global talker
if talker is None:
talker = pyttsx3.init()
talker.setProperty('voice', talker.getProperty('voices')[1].id)
talker.setProperty('volume', 0.2)
talker.setProperty('rate', 160)
talker.say(text)
talker.runAndWait()
6 changes: 6 additions & 0 deletions ideas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
- Also once lintception is updated with allowing the user to specify certain files that should
be empty, specify the __init__.py in the hypickle folder.

# If an arg player is online, output a voice message for their most recent game as well.

# If an arg player is online and their recentgames list has a new first dict, voice-output that
they've entered/exited a game since the last check.
# Would have to keep track of the result from the previous call to the recentgames endpoint.

# Can include some linters mentioned here in your tests as well (e.g., bandit):
https://realpython.com/python-code-quality/

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"rich",
"deepdiff",
"mplcursors",
"pyttsx3",
]
readme = "README.md"

Expand Down

0 comments on commit 6a7bac8

Please sign in to comment.