diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8750353..6a28cc0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 diff --git a/README.md b/README.md index 6422b37..3abd923 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/hypickle/Player.py b/hypickle/Player.py index 4246838..ee1d65d 100644 --- a/hypickle/Player.py +++ b/hypickle/Player.py @@ -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() diff --git a/hypickle/Utils.py b/hypickle/Utils.py index dbd87f6..73f1fca 100644 --- a/hypickle/Utils.py +++ b/hypickle/Utils.py @@ -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) @@ -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() != '' \ No newline at end of file + 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() \ No newline at end of file diff --git a/ideas.txt b/ideas.txt index e144390..be728cd 100644 --- a/ideas.txt +++ b/ideas.txt @@ -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/ diff --git a/pyproject.toml b/pyproject.toml index d48a07f..34d9b83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "rich", "deepdiff", "mplcursors", + "pyttsx3", ] readme = "README.md"