Initial commit
This commit is contained in:
commit
03705af018
|
@ -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'])
|
||||||
|
|
|
@ -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]])
|
Loading…
Reference in New Issue