commit 03705af018fbbf5462649dc8fd97e0e910aa7927 Author: Pedro de Oliveira Date: Sun May 5 04:47:47 2019 +0100 Initial commit diff --git a/getstations.py b/getstations.py new file mode 100755 index 0000000..2f63855 --- /dev/null +++ b/getstations.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import json +import re +import requests + +request = requests.get('http://www.ipma.pt/pt/index.html') + +MATCH = re.search(r"var stations=(.*?)\;", request.text, re.DOTALL) + +""" +text_file = open("bleh.json", "w") +text_file.write(MATCH.group(1)) +text_file.close() +""" + +stations = json.loads(MATCH.group(1)) + +for s in stations: + print(s['properties']['idEstacao'], s['properties']['localEstacao']) + diff --git a/getvalues.py b/getvalues.py new file mode 100755 index 0000000..368f36f --- /dev/null +++ b/getvalues.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import json +import re +import sys +import requests + +request = requests.get('http://www.ipma.pt/pt/index.html') + +MATCH = re.search(r"var data = ({.*?)\;", request.text, re.DOTALL) + +""" +text_file = open("bleh.json", "w") +text_file.write(MATCH.group(1)) +text_file.close() +""" + +data = json.loads(MATCH.group(1)) +days = [] +for d in data: + days.append(d) + days = sorted(days, reverse=True) + +# List all available days on the site +# ./getvalues.py days +if len(sys.argv) == 2 and sys.argv[1] == "days": + print(days) + +# Lists data for all the days for a specific weather station +# ./getvalues.py 773 +if len(sys.argv) == 2 and sys.argv[1].isnumeric(): + for d in days: + if data[d][sys.argv[1]] is not None: + print(d, data[d][sys.argv[1]]) + +# Prints the data for a specific day and a specific weather station +# ./getvalues.py 2019-03-29 773 +if len(sys.argv) == 3: + print(data[sys.argv[1]][sys.argv[2]])