Skip to content

Instantly share code, notes, and snippets.

@mishailovic
Created January 13, 2022 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishailovic/3fe9766b9af37a77cc793853e5bb1a68 to your computer and use it in GitHub Desktop.
Save mishailovic/3fe9766b9af37a77cc793853e5bb1a68 to your computer and use it in GitHub Desktop.
from .. import loader, utils # pylint: disable=relative-beyond-top-level
import logging
import requests
logger = logging.getLogger(__name__)
def register(cb):
cb(WWTrMod())
@loader.tds
class WWWTrMod(loader.Module):
"""Get weather using wttr.in"""
strings = {"name": "wttr", "processing": "Getting weather..."}
@loader.unrestricted
async def wttrcmd(self, message):
""".wttr <city> for weather
can also work with multiple cities separated with spaces"""
city = utils.get_args(message)
if city:
msg_text = []
msg = await utils.answer(message, self.strings("processing", message))
for i in city:
r = requests.get("https://wttr.in/" + i + "?format=%l:+%c+%t,+%w+%m&m")
msg_text.append(r.text)
await msg[0].edit("\n".join(msg_text))
else:
msg = await utils.answer(message, self.strings("processing", message))
r = requests.get("https://wttr.in/?format=%l:+%c+%t,+%w+%m&m")
await msg[0].edit(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment