Initial commit

This commit is contained in:
Pedro de Oliveira 2019-05-05 04:47:47 +01:00
commit 03705af018
2 changed files with 62 additions and 0 deletions

22
getstations.py Executable file
View File

@ -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'])

40
getvalues.py Executable file
View File

@ -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]])