From b0c515761c920f9441e31f1768edfb46e13c7716 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Sun, 22 Aug 2021 18:44:32 +0200 Subject: [PATCH] Fixed bug when jarvis wouldn't start outside pycharm --- .gitignore | 2 +- jarvis/__init__.py | 3 +++ jarvis/main.py | 3 ++- jarvis/skills/__init__.py | 6 +++--- jarvis/skills/entertainement/spotify/__init__.py | 6 ++++-- run.py | 11 +++++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 run.py diff --git a/.gitignore b/.gitignore index 6f9279f..55cf675 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ __pycache__/ *.so intent_cache/* -**/intent_cache/** +intent_cache/** # Distribution / packaging diff --git a/jarvis/__init__.py b/jarvis/__init__.py index e69de29..0705d59 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -0,0 +1,3 @@ +import sys + +sys.path.append('../') diff --git a/jarvis/main.py b/jarvis/main.py index 622e914..d54842d 100644 --- a/jarvis/main.py +++ b/jarvis/main.py @@ -10,7 +10,8 @@ from jarvis.skills.productivity.speedtest import SpeedTestSkill from jarvis.skills.research.wikipedia import WikipediaSkill from jarvis.utils import languages_utils, flask_utils -if __name__ == '__main__': + +def start(): # Load lingua franca in the memory # Supported : English French German Hungarian Italian Portuguese Swedish lingua_franca.load_language(lang=languages_utils.get_language_only_country()) diff --git a/jarvis/skills/__init__.py b/jarvis/skills/__init__.py index 6af1fde..e35c298 100644 --- a/jarvis/skills/__init__.py +++ b/jarvis/skills/__init__.py @@ -4,9 +4,9 @@ import random import threading import types -from jarvis import get_path_file -from jarvis.skills import intent_manager -from jarvis.utils import languages_utils, client_utils +from .. import get_path_file +from ..skills import intent_manager +from ..utils import languages_utils, client_utils class Skill: diff --git a/jarvis/skills/entertainement/spotify/__init__.py b/jarvis/skills/entertainement/spotify/__init__.py index d37efef..d49a572 100644 --- a/jarvis/skills/entertainement/spotify/__init__.py +++ b/jarvis/skills/entertainement/spotify/__init__.py @@ -15,8 +15,10 @@ class SpotifySkill(Skill, metaclass=SkillRegistering): data['artist'] if 'artist' in data else None) if song_lists_matching is not None and len(song_lists_matching) >= 1: - # pause the music then speak dialog - spotify.get_spotify().pause_playback() + + # pause the music before speaking dialog + if spotify.is_music_playing(): + spotify.get_spotify().pause_playback() if 'artist' in data and 'song' not in data: self.speak_dialog("play_from_artist", {'artist': song_lists_matching[0]['artists'][0]['name']}) diff --git a/run.py b/run.py new file mode 100644 index 0000000..8a75cc5 --- /dev/null +++ b/run.py @@ -0,0 +1,11 @@ +import os +import sys + +# TODO: see if something better could be done +if __name__ == '__main__': + sys.path.append(os.path.realpath('..')) + + # doing the import after editing the path otherwise cause issue between running in pycharm or the terminal + from jarvis.main import start + + start()