Last active
March 31, 2019 23:19
-
-
Save falsovsky/aa5423db4c71ff3dbfeeff48b9102ed5 to your computer and use it in GitHub Desktop.
IPMA
This file contains hidden or 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/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) | |
stations = json.loads(MATCH.group(1)) | |
for s in stations: | |
print(s['properties']['idEstacao'], s['properties']['localEstacao']) |
This file contains hidden or 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/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) | |
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]]) |
This file contains hidden or 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
./getstations.py |grep -i almada | |
773 Almada, P.Rainha | |
falso@orangepipc ~/src/ipma $ ./getvalues.py days | |
['2019-03-30', '2019-03-29', '2019-03-28', '2019-03-27', '2019-03-26', '2019-03-25', '2019-03-24', '2019-03-23', '2019-03-22', '2019-03-21'] | |
falso@orangepipc ~/src/ipma $ ./getvalues.py 773 | |
2019-03-29 {'hum_min': 24.0, 'idDireccVento': 2, 'temp_med': 14.9, 'pressao': -99.0, 'vento_int_max_inst': 31.7, 'temp_min': 6.9, 'rad_total': 21655.5, 'temp_max': 22.3, 'vento_int_med': 9.7, 'hum_med': 63.0, 'vento_dir_max': 51, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 97.0} | |
2019-03-28 {'hum_min': 25.0, 'idDireccVento': 1, 'temp_med': 14.3, 'pressao': -99.0, 'vento_int_max_inst': 30.2, 'temp_min': 5.8, 'rad_total': 22637.7, 'temp_max': 24.2, 'vento_int_med': 7.6, 'hum_med': 71.0, 'vento_dir_max': 62, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 100.0} | |
2019-03-27 {'hum_min': 13.0, 'idDireccVento': 1, 'temp_med': 17.1, 'pressao': -99.0, 'vento_int_max_inst': 33.8, 'temp_min': 7.6, 'rad_total': 22395.1, 'temp_max': 25.4, 'vento_int_med': 9.0, 'hum_med': 51.0, 'vento_dir_max': 129, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 82.0} | |
2019-03-26 {'hum_min': 21.0, 'idDireccVento': 1, 'temp_med': 17.9, 'pressao': -99.0, 'vento_int_max_inst': 47.9, 'temp_min': 10.6, 'rad_total': 19552.6, 'temp_max': 25.6, 'vento_int_med': 13.0, 'hum_med': 41.0, 'vento_dir_max': 56, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 81.0} | |
2019-03-25 {'hum_min': 19.0, 'idDireccVento': 1, 'temp_med': 17.8, 'pressao': -99.0, 'vento_int_max_inst': 35.6, 'temp_min': 6.7, 'rad_total': 21934.2, 'temp_max': 27.0, 'vento_int_med': 11.5, 'hum_med': 52.0, 'vento_dir_max': 62, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 97.0} | |
2019-03-24 {'hum_min': 27.0, 'idDireccVento': 1, 'temp_med': 16.8, 'pressao': -99.0, 'vento_int_max_inst': 32.4, 'temp_min': 9.4, 'rad_total': 20459.0, 'temp_max': 24.0, 'vento_int_med': 9.4, 'hum_med': 56.0, 'vento_dir_max': 34, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 94.0} | |
2019-03-23 {'hum_min': 21.0, 'idDireccVento': 1, 'temp_med': 17.4, 'pressao': -99.0, 'vento_int_max_inst': 36.0, 'temp_min': 11.5, 'rad_total': 20778.5, 'temp_max': 25.4, 'vento_int_med': 10.4, 'hum_med': 45.0, 'vento_dir_max': 118, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 66.0} | |
2019-03-22 {'hum_min': 23.0, 'idDireccVento': 1, 'temp_med': 14.4, 'pressao': -99.0, 'vento_int_max_inst': 34.2, 'temp_min': 4.1, 'rad_total': 22074.0, 'temp_max': 22.6, 'vento_int_med': 11.9, 'hum_med': 55.0, 'vento_dir_max': 51, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 99.0} | |
2019-03-21 {'hum_min': 48.0, 'idDireccVento': 1, 'temp_med': 12.9, 'pressao': -99.0, 'vento_int_max_inst': 38.2, 'temp_min': 4.1, 'rad_total': 21172.6, 'temp_max': 19.4, 'vento_int_med': 8.6, 'hum_med': 73.0, 'vento_dir_max': 56, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 97.0} | |
falso@orangepipc ~/src/ipma $ ./getvalues.py 2019-03-29 773 | |
{'hum_min': 24.0, 'idDireccVento': 2, 'temp_med': 14.9, 'pressao': -99.0, 'vento_int_max_inst': 31.7, 'temp_min': 6.9, 'rad_total': 21655.5, 'temp_max': 22.3, 'vento_int_med': 9.7, 'hum_med': 63.0, 'vento_dir_max': 51, 'prec_max_inst': 0.0, 'prec_quant': 0.0, 'hum_max': 97.0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment