První verze pluginu mxchat_weather
This commit is contained in:
parent
3f59e4acf8
commit
3d3829a505
9
LICENSE
9
LICENSE
@ -1,9 +1,6 @@
|
|||||||
MIT License
|
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:
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
...
|
||||||
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.
|
|
33
README.md
33
README.md
@ -1,3 +1,34 @@
|
|||||||
# mxchat_weather
|
# mxchat_weather
|
||||||
|
|
||||||
Jednoduchý Maubot plugin pro zobrazení počasí pomocí příkazu !pocasi
|
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`
|
2
config.yaml
Normal file
2
config.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
api_key: "sem-dosadíš-svůj-klíč-z-openweathermap"
|
||||||
|
default_location: "Sokolov"
|
8
maubot.yaml
Normal file
8
maubot.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
id: com.archos.weather
|
||||||
|
version: 0.1.0
|
||||||
|
license: MIT
|
||||||
|
modules:
|
||||||
|
- weather
|
||||||
|
main_class: WeatherBot
|
||||||
|
config: true
|
||||||
|
extra_files: []
|
29
weather.py
Normal file
29
weather.py
Normal file
@ -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.")
|
Loading…
x
Reference in New Issue
Block a user