Last active
January 11, 2019 08:25
-
-
Save Petteri/c4be51516a723ee3cd90901c919bba22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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