diff --git a/app/audio/sound_level.py b/app/audio/sound_level.py index 1ccd624..9939d49 100644 --- a/app/audio/sound_level.py +++ b/app/audio/sound_level.py @@ -74,19 +74,23 @@ def _command_exists(command): True, если команда существует """ try: - subprocess.run(["which", command], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - check=False) - return True + result = subprocess.run( + ["which", command], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=False, + ) + return result.returncode == 0 except: try: # Альтернативная проверка для Windows - subprocess.run(["where", command], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - check=False) - return True + result = subprocess.run( + ["where", command], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=False, + ) + return result.returncode == 0 except: return False diff --git a/app/core/ai.py b/app/core/ai.py index b43dd7b..5be899c 100644 --- a/app/core/ai.py +++ b/app/core/ai.py @@ -38,6 +38,8 @@ def _send_request(messages, max_tokens, temperature, error_text): temperature: "Креативность" (0.2 - строго, 1.0 - креативно). error_text: Текст ошибки для пользователя в случае сбоя. """ + if not PERPLEXITY_API_KEY: + return "Не настроен PERPLEXITY_API_KEY. Проверьте файл .env." headers = { "Authorization": f"Bearer {PERPLEXITY_API_KEY}", "Content-Type": "application/json", @@ -102,6 +104,9 @@ def ask_ai_stream(messages_history: list): """ Generator that yields chunks of the AI response as they arrive. """ + if not PERPLEXITY_API_KEY: + yield "Не настроен ключ PERPLEXITY_API_KEY. Проверьте файл .env." + return if not messages_history: yield "Извините, я не расслышал вашу команду." return diff --git a/app/features/music.py b/app/features/music.py index 5f7afc2..254032a 100644 --- a/app/features/music.py +++ b/app/features/music.py @@ -271,7 +271,12 @@ class SpotifyMusicController: r"(следующ|дальше|скип|пропусти|next|skip)", ] for pattern in next_patterns: - if re.search(pattern, text_lower) and "трек" in text_lower or "песн" in text_lower or "skip" in text_lower or "next" in text_lower: + if re.search(pattern, text_lower) and ( + "трек" in text_lower + or "песн" in text_lower + or "skip" in text_lower + or "next" in text_lower + ): return self.next_track() # Предыдущий трек diff --git a/app/features/weather.py b/app/features/weather.py index 36d1974..9196e55 100644 --- a/app/features/weather.py +++ b/app/features/weather.py @@ -427,13 +427,18 @@ def get_weather_report(requested_city: str = None) -> str: report += f" Сегодня температура будет от {get_temperature_text(t_min)} до {get_temperature_text(t_max)}." # --- 3. Forecast Next 4 Hours --- - current_hour = datetime.now().hour hourly_temps = data["hourly"]["temperature_2m"] hourly_precip = data["hourly"]["precipitation"] hourly_codes = data["hourly"]["weather_code"] + hourly_times = data["hourly"].get("time", []) - # Start from next hour - start_idx = current_hour + 1 + # Start from the next hour based on the API's current time (timezone-aware for the location). + current_time_iso = data.get("current", {}).get("time") + if current_time_iso and current_time_iso in hourly_times: + start_idx = hourly_times.index(current_time_iso) + 1 + else: + current_hour = datetime.now().hour + start_idx = current_hour + 1 end_idx = min(start_idx + 4, len(hourly_temps)) next_temps = hourly_temps[start_idx:end_idx] @@ -484,4 +489,4 @@ def get_weather_report(requested_city: str = None) -> str: return f"Получены некорректные данные о погоде." except Exception as e: print(f"❌ Ошибка получения погоды: {e}") - return "Не удалось получить полные данные о погоде." \ No newline at end of file + return "Не удалось получить полные данные о погоде." diff --git a/app/main.py b/app/main.py index 93cd40d..c31126e 100644 --- a/app/main.py +++ b/app/main.py @@ -49,6 +49,7 @@ from .audio.wakeword import ( stop_monitoring as stop_wakeword_monitoring, ) from .core.ai import ask_ai_stream, translate_text +from .core.config import BASE_DIR from .core.cleaner import clean_response from .core.commands import is_stop_command from .features.alarm import get_alarm_clock @@ -164,9 +165,9 @@ def main(): except Exception as exc: print(f"Warning: pygame mixer init failed; sound effects disabled. ({exc})") else: - ding_sound_path = "assets/sounds/ding.wav" - if os.path.exists(ding_sound_path): - ding_sound = mixer.Sound(ding_sound_path) + ding_sound_path = BASE_DIR / "assets" / "sounds" / "ding.wav" + if ding_sound_path.exists(): + ding_sound = mixer.Sound(str(ding_sound_path)) ding_sound.set_volume(0.3) else: print(f"⚠️ Звук {ding_sound_path} не найден")