Skip to content

Instantly share code, notes, and snippets.

@AshyIsMe
Created January 26, 2022 03:05
Show Gist options
  • Save AshyIsMe/6676f392326bc6aef4a3a06287d95e5d to your computer and use it in GitHub Desktop.
Save AshyIsMe/6676f392326bc6aef4a3a06287d95e5d to your computer and use it in GitHub Desktop.
Single line of weather from wttr.in
#!/usr/bin/env python3
from urllib.parse import quote
import subprocess
def wttr(location):
c = "curl wttr.in/" + quote(location) + '?0TQ'
r = subprocess.run(c, shell=True, stdout=subprocess.PIPE)
l = r.stdout.decode('utf-8').split('\n')
w = ' '.join([s[16:].strip() for s in l])
return w + '$ ' + c
def main():
print( wttr('brisbane') )
if __name__=="__main__":
main()
@AshyIsMe
Copy link
Author

Sopel module

I think it might be this simple. Untested currently

sopel-wttr.py

#!/usr/bin/env python3

from urllib.parse import quote
import sopel
import subprocess
import sys

def wttr(location):
    c = "curl -s wttr.in/" + quote(location) + '?0TQ'
    r = subprocess.run(c, shell=True, stdout=subprocess.PIPE)
    l = r.stdout.decode('utf-8').split('\n')
    w = ' '.join([s[16:].strip() for s in l])
    return w + '$ ' + c

@sopel.module.commands('wttr', 'weather')
def sopel_wttr(bot, trigger):
    bot.reply(wttr(trigger.group(2)))


def main():
    #print( wttr('brisbane') )
    l = ' '.join(sys.argv[1:])
    print(wttr(l))


if __name__=="__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment