diff --git a/LICENSE b/LICENSE index 0b920ba..7d80f4a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,6 @@ MIT License -Copyright (c) 2025 Oscloud +Copyright (c) 2025 Archos -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Permission is hereby granted, free of charge, to any person obtaining a copy +... \ No newline at end of file diff --git a/README.md b/README.md index cb69d63..a82a360 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,34 @@ # mxchat_weather -Jednoduchý Maubot plugin pro zobrazení počasí pomocí příkazu !pocasi \ No newline at end of file +Jednoduchý Maubot plugin pro Matrix, který umožňuje zobrazit aktuální počasí ve zvoleném městě pomocí příkazu `!pocasi`. + +## 📦 Instalace + +1. Nahraj plugin do Maubotu přes webové rozhraní (`.mbp` build viz níže) +2. Vytvoř instanci bota s tímto pluginem +3. Do configu zadej svůj API klíč z [OpenWeatherMap](https://openweathermap.org/api) + +```yaml +api_key: "tvůj_api_klíč" +default_location: "Sokolov" +``` + +## 💬 Použití + +``` +!pocasi # zobrazí počasí pro výchozí město +!pocasi Brno # zobrazí počasí pro zadané město +``` + +## 🛠 Build `.mbp` balíčku + +```bash +pip install maubot +mbc build +``` + +Soubor `com.archos.weather-v0.1.0.mbp` poté nahraj do Maubotu jako plugin. + +--- + +Archos © 2025 — součást komunitního projektu `mxchat.cz` \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..0d37516 --- /dev/null +++ b/config.yaml @@ -0,0 +1,2 @@ +api_key: "sem-dosadíš-svůj-klíč-z-openweathermap" +default_location: "Sokolov" \ No newline at end of file diff --git a/maubot.yaml b/maubot.yaml new file mode 100644 index 0000000..8939e4b --- /dev/null +++ b/maubot.yaml @@ -0,0 +1,8 @@ +id: com.archos.weather +version: 0.1.0 +license: MIT +modules: + - weather +main_class: WeatherBot +config: true +extra_files: [] \ No newline at end of file diff --git a/weather.py b/weather.py new file mode 100644 index 0000000..89b0863 --- /dev/null +++ b/weather.py @@ -0,0 +1,29 @@ +from maubot import Plugin, MessageEvent +from maubot.handlers import command +import aiohttp + +class WeatherBot(Plugin): + @command.new("pocasi", help="Zobrazí aktuální počasí pro dané město") + async def pocasi(self, evt: MessageEvent, args: str = None) -> None: + city = args if args else self.config.get("default_location", "Sokolov") + api_key = self.config.get("api_key") + + if not api_key: + await evt.reply("API klíč pro OpenWeatherMap není nastaven.") + return + + url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric&lang=cz" + async with aiohttp.ClientSession() as session: + async with session.get(url) as resp: + if resp.status != 200: + await evt.reply(f"Nepodařilo se načíst počasí pro {city}.") + return + data = await resp.json() + + try: + weather = data["weather"][0]["description"] + temp = data["main"]["temp"] + wind = data["wind"]["speed"] + await evt.reply(f"Počasí v {city}: {temp}°C, {weather}, vítr {wind} m/s") + except KeyError: + await evt.reply("Chyba při čtení dat z API.") \ No newline at end of file