add_weather_functions #7
@@ -8,3 +8,7 @@ PICOVOICE_TOKEN='token'
|
|||||||
# home assistant
|
# home assistant
|
||||||
HOME_ASSISTANT_URL='http://localhost:8123/api'
|
HOME_ASSISTANT_URL='http://localhost:8123/api'
|
||||||
HOME_ASSISTANT_TOKEN=''
|
HOME_ASSISTANT_TOKEN=''
|
||||||
|
|
||||||
|
# weather
|
||||||
|
WEATHER_DEFAULT_CITY='krasnoyarsk'
|
||||||
|
WEATHER_URL='https://yandex.ru/pogoda'
|
||||||
@@ -46,6 +46,7 @@ music_on:
|
|||||||
- хочу послушать музыку
|
- хочу послушать музыку
|
||||||
- запусти плейлист
|
- запусти плейлист
|
||||||
music_off:
|
music_off:
|
||||||
|
- пауза
|
||||||
- выключи музыку
|
- выключи музыку
|
||||||
- остановить музыку
|
- остановить музыку
|
||||||
- пауза музыки
|
- пауза музыки
|
||||||
|
|||||||
@@ -13,3 +13,7 @@ PICOVOICE_TOKEN = env.str("PICOVOICE_TOKEN")
|
|||||||
# home assistant
|
# home assistant
|
||||||
HOME_ASSISTANT_URL = env.str("HOME_ASSISTANT_URL")
|
HOME_ASSISTANT_URL = env.str("HOME_ASSISTANT_URL")
|
||||||
HOME_ASSISTANT_TOKEN = env.str("HOME_ASSISTANT_TOKEN")
|
HOME_ASSISTANT_TOKEN = env.str("HOME_ASSISTANT_TOKEN")
|
||||||
|
|
||||||
|
# weather
|
||||||
|
WEATHER_DEFAULT_CITY = env.str("WEATHER_DEFAULT_CITY")
|
||||||
|
WEATHER_URL = env.str("WEATHER_URL")
|
||||||
|
|||||||
+2
-1
@@ -11,7 +11,7 @@ from fuzzywuzzy import fuzz
|
|||||||
from pvrecorder import PvRecorder
|
from pvrecorder import PvRecorder
|
||||||
|
|
||||||
from data import config
|
from data import config
|
||||||
from modules import HomeAssistant, MediaPlayerController
|
from modules import HomeAssistant, MediaPlayerController, Weather
|
||||||
from utils import download_models, execute_cmd, play
|
from utils import download_models, execute_cmd, play
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@ class Jarvis:
|
|||||||
self.VA_CMD_LIST = yaml.safe_load(open('data/commands.yaml', encoding='utf8'))
|
self.VA_CMD_LIST = yaml.safe_load(open('data/commands.yaml', encoding='utf8'))
|
||||||
self.home_assistant = HomeAssistant.HomeAssistant()
|
self.home_assistant = HomeAssistant.HomeAssistant()
|
||||||
self.media_player_controller = MediaPlayerController.MediaPlayerController()
|
self.media_player_controller = MediaPlayerController.MediaPlayerController()
|
||||||
|
self.weather = Weather.Weather()
|
||||||
self.porcupine = pvporcupine.create(
|
self.porcupine = pvporcupine.create(
|
||||||
access_key=config.PICOVOICE_TOKEN,
|
access_key=config.PICOVOICE_TOKEN,
|
||||||
keywords=['jarvis'],
|
keywords=['jarvis'],
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from curl_cffi import requests
|
||||||
|
|
||||||
|
from data.config import WEATHER_DEFAULT_CITY, WEATHER_URL
|
||||||
|
|
||||||
|
|
||||||
|
class Weather:
|
||||||
|
def __init__(self):
|
||||||
|
self.default_city = WEATHER_DEFAULT_CITY
|
||||||
|
self.url = WEATHER_URL
|
||||||
|
|
||||||
|
def get_info(self, city: str) -> str:
|
||||||
|
response = requests.get(f"{self.url}/{city}", impersonate="chrome110")
|
||||||
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
card = soup.find("div", class_=["fact", "fact_prec_rain-low", "card", "card_size_big"])
|
||||||
|
info = card.find("div", class_=["fact__temp-wrap"])
|
||||||
|
temp = info.find("span", class_=["temp__value", "temp__value_with-unit"]).text
|
||||||
|
weather = info.find("div", class_=["link__condition", "day-anchor i-bem"]).text.lower()
|
||||||
|
return f"За окном {temp}, {weather}"
|
||||||
|
|
||||||
|
def validate_city(self, voice: str) -> str:
|
||||||
|
return self.default_city
|
||||||
Generated
+86
-1
@@ -44,6 +44,41 @@ files = [
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
test = ["tox"]
|
test = ["tox"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "beautifulsoup4"
|
||||||
|
version = "4.12.3"
|
||||||
|
description = "Screen-scraping library"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6.0"
|
||||||
|
files = [
|
||||||
|
{file = "beautifulsoup4-4.12.3-py3-none-any.whl", hash = "sha256:b80878c9f40111313e55da8ba20bdba06d8fa3969fc68304167741bbf9e082ed"},
|
||||||
|
{file = "beautifulsoup4-4.12.3.tar.gz", hash = "sha256:74e3d1928edc070d21748185c46e3fb33490f22f52a3addee9aee0f4f7781051"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
soupsieve = ">1.2"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
cchardet = ["cchardet"]
|
||||||
|
chardet = ["chardet"]
|
||||||
|
charset-normalizer = ["charset-normalizer"]
|
||||||
|
html5lib = ["html5lib"]
|
||||||
|
lxml = ["lxml"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bs4"
|
||||||
|
version = "0.0.2"
|
||||||
|
description = "Dummy package for Beautiful Soup (beautifulsoup4)"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "bs4-0.0.2-py2.py3-none-any.whl", hash = "sha256:abf8742c0805ef7f662dce4b51cca104cffe52b835238afc169142ab9b3fbccc"},
|
||||||
|
{file = "bs4-0.0.2.tar.gz", hash = "sha256:a48685c58f50fe127722417bae83fe6badf500d54b55f7e39ffe43b798653925"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
beautifulsoup4 = "*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "certifi"
|
name = "certifi"
|
||||||
version = "2024.2.2"
|
version = "2024.2.2"
|
||||||
@@ -303,6 +338,34 @@ mypy = ["contourpy[bokeh,docs]", "docutils-stubs", "mypy (==1.8.0)", "types-Pill
|
|||||||
test = ["Pillow", "contourpy[test-no-images]", "matplotlib"]
|
test = ["Pillow", "contourpy[test-no-images]", "matplotlib"]
|
||||||
test-no-images = ["pytest", "pytest-cov", "pytest-xdist", "wurlitzer"]
|
test-no-images = ["pytest", "pytest-cov", "pytest-xdist", "wurlitzer"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "curl-cffi"
|
||||||
|
version = "0.6.3"
|
||||||
|
description = "libcurl ffi bindings for Python, with impersonation support."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-macosx_10_9_x86_64.whl", hash = "sha256:ac60ac08f07640bd9ee6ee44310748931a3d49a7c8e878745f1817b46ff0719d"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:d78a609c3b984df9a14022c0b5fc59c1c643c39fc4cb9100e110f7551339a194"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:760b7b837c86626f2c9518c3bad42aad3b6ccb455499b648bc98e8dee9f73891"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5423c2f53f8889bcc9ce42455fc1c0c9487b480944f66aaa6ed5ce81e0fc5540"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4b4712bc9a8a0d933aef7051eaa5448b9a1c662f25dd83967dbdd46aa3e418c0"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:5d659acbe051805b9f9c82a7725d534b5842c1a9291159e7733e7c92782ef80b"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:ea9b04df071368d13b02c51e87e3e51b46b924be61681fc280cb9633b42dac2c"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-win32.whl", hash = "sha256:0f37e3d761e37173462dbc95ae4216165dacef21f0d9ab6bb6802003516a156f"},
|
||||||
|
{file = "curl_cffi-0.6.3-cp38-abi3-win_amd64.whl", hash = "sha256:dd36513cd46eb8f2751d45e3aa47a989421d3f3a2bcc54abab487ae38549d91b"},
|
||||||
|
{file = "curl_cffi-0.6.3.tar.gz", hash = "sha256:0d2d07467590d66982f29a8dc9050b6a1f41a6c4bb44dcbf24108b13cf71a797"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
certifi = ">=2024.2.2"
|
||||||
|
cffi = ">=1.12.0"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
build = ["cibuildwheel", "wheel"]
|
||||||
|
dev = ["autoflake (==1.4)", "charset-normalizer (>=3.3.2,<4)", "coverage (==6.4.1)", "cryptography (==38.0.3)", "flake8 (==6.0.0)", "flake8-bugbear (==22.7.1)", "flake8-pie (==0.15.0)", "httpx (==0.23.1)", "mypy (==1.9.0)", "pytest (==7.1.2)", "pytest-asyncio (==0.19.0)", "pytest-trio (==0.7.0)", "ruff (==0.3.3)", "trio (==0.21.0)", "trio-typing (==0.7.0)", "trustme (==0.9.0)", "types-certifi (==2021.10.8.2)", "uvicorn (==0.18.3)", "websockets (==11.0.3)"]
|
||||||
|
test = ["charset-normalizer (>=3.3.2,<4)", "cryptography (==38.0.3)", "fastapi (==0.100.0)", "httpx (==0.23.1)", "proxy.py (==2.4.3)", "pytest (==7.1.2)", "pytest-asyncio (==0.19.0)", "pytest-trio (==0.7.0)", "python-multipart (==0.0.6)", "trio (==0.21.0)", "trio-typing (==0.7.0)", "trustme (==0.9.0)", "types-certifi (==2021.10.8.2)", "uvicorn (==0.18.3)", "websockets (==11.0.3)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cycler"
|
name = "cycler"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -349,6 +412,17 @@ dev = ["environs[tests]", "pre-commit (>=3.5,<4.0)", "tox"]
|
|||||||
django = ["dj-database-url", "dj-email-url", "django-cache-url"]
|
django = ["dj-database-url", "dj-email-url", "django-cache-url"]
|
||||||
tests = ["environs[django]", "pytest"]
|
tests = ["environs[django]", "pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fake-useragent"
|
||||||
|
version = "1.5.1"
|
||||||
|
description = "Up-to-date simple useragent faker with real world database"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "fake-useragent-1.5.1.tar.gz", hash = "sha256:6387269f5a2196b5ba7ed8935852f75486845a1c95c50e72460e6a8e762f5c49"},
|
||||||
|
{file = "fake_useragent-1.5.1-py3-none-any.whl", hash = "sha256:57415096557c8a4e23b62a375c21c55af5fd4ba30549227f562d2c4f5b60e3b3"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filelock"
|
name = "filelock"
|
||||||
version = "3.13.4"
|
version = "3.13.4"
|
||||||
@@ -2144,6 +2218,17 @@ cffi = ">=1.0"
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
numpy = ["numpy"]
|
numpy = ["numpy"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "soupsieve"
|
||||||
|
version = "2.5"
|
||||||
|
description = "A modern CSS selector implementation for Beautiful Soup."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "soupsieve-2.5-py3-none-any.whl", hash = "sha256:eaa337ff55a1579b6549dc679565eac1e3d000563bcb1c8ab0d0fefbc0c2cdc7"},
|
||||||
|
{file = "soupsieve-2.5.tar.gz", hash = "sha256:5663d5a7b3bfaeee0bc4372e7fc48f9cff4940b3eec54a6451cc5299f1097690"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "soxr"
|
name = "soxr"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -2499,4 +2584,4 @@ files = [
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "f3829914195ce01bfac29dea5117fb3f28f095ecc6081a77eddb6bacc895718b"
|
content-hash = "6f3eb835443eb7b57269560a3102a4908b74be505b5d4dbf962431270efe2eea"
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ ollama = "^0.1.6"
|
|||||||
ruff = "^0.4.2"
|
ruff = "^0.4.2"
|
||||||
noisereduce = "^3.0.2"
|
noisereduce = "^3.0.2"
|
||||||
environs = "^11.0.0"
|
environs = "^11.0.0"
|
||||||
|
bs4 = "^0.0.2"
|
||||||
|
fake-useragent = "^1.5.1"
|
||||||
|
curl-cffi = "^0.6.3"
|
||||||
|
|
||||||
|
|
||||||
[[tool.poetry.source]]
|
[[tool.poetry.source]]
|
||||||
|
|||||||
+13
-1
@@ -1,4 +1,12 @@
|
|||||||
def execute_cmd(self, cmd: str, recognized_phrase: str, voice: str) -> None:
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from modules.Jarvis import Jarvis
|
||||||
|
else:
|
||||||
|
Jarvis = None
|
||||||
|
|
||||||
|
|
||||||
|
def execute_cmd(self: Jarvis, cmd: str, recognized_phrase: str, voice: str) -> None:
|
||||||
"""
|
"""
|
||||||
Функция выполняет полученные команды
|
Функция выполняет полученные команды
|
||||||
|
|
||||||
@@ -30,3 +38,7 @@ def execute_cmd(self, cmd: str, recognized_phrase: str, voice: str) -> None:
|
|||||||
entity_name = self.home_assistant.voice_to_name(voice)
|
entity_name = self.home_assistant.voice_to_name(voice)
|
||||||
entity_info = self.home_assistant.validate_info(entity_name)
|
entity_info = self.home_assistant.validate_info(entity_name)
|
||||||
print(entity_info)
|
print(entity_info)
|
||||||
|
elif cmd == 'weather':
|
||||||
|
city = self.weather.validate_city(voice)
|
||||||
|
city_info = self.weather.get_info(city)
|
||||||
|
print(city_info)
|
||||||
|
|||||||
Reference in New Issue
Block a user