Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python3
import sys
import subprocess
def get_weather(city, place=""):
m = "2"
grep = city
delimiter = ""
if place == "" and city.find("/") > -1:
city, place = city.split("/", 1)
if place != "":
delimiter = "/"
m = "1"
grep = place
try:
out = subprocess.check_output("w3m -dump https://ilmatieteenlaitos.fi/saa/%s%s%s|grep -m%s -A5 -i %s|grep -A5 °" % \
(city, delimiter, place, m, grep),
shell=True)
except:
raise
return "Jotain meni pieleen (%s%s%s)" % (city, delimiter, place)
out = out.strip()
out = out.split()
out = [o.decode("utf-8") for o in out]
return "Lämpötila|tuntuu|sade%%|aurinkoista|tuuli|sademäärä: %s" % (" ".join(out))
if __name__ == "__main__":
if len(sys.argv) == 3:
print(get_weather(sys.argv[1], sys.argv[2]))
elif len(sys.argv) == 2:
print(get_weather(sys.argv[1]))
else:
print("Ei tarpeeksi argumentteja: %s <kaupunki> <paikka>", sys.argv[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.