Last active
February 14, 2020 12:49
-
-
Save Wanhenri/abd2ca4e4fd6a08ff4eb64e1c2d22299 to your computer and use it in GitHub Desktop.
read txt and convert for json file
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
import requests | |
import json | |
dateInmet="2020021407" | |
def get_inmet(dateInmet): | |
url = "http://tempook.com.br/DATABASE/UND_inmet_"+ str(dateInmet) +"00.txt" | |
r = requests.get(url).text | |
d = dict() | |
for l in r.splitlines(): | |
s = l.split() | |
d[s[0]] = { | |
"Ano":s[4], | |
"Mes":s[5], | |
"Dia":s[6], | |
"Hora":s[7], | |
"Latitude": s[1], | |
"Longitude": s[2], | |
"Altitude": s[3], | |
"Temp":s[8], | |
"Tmax":s[9], | |
"Tmin":s[10], | |
"UR":s[11], | |
"URmax":s[12], | |
"URmin":s[13], | |
"Prec":s[24] | |
} | |
return json.dumps(d, indent=2) | |
application = get_inmet(dateInmet) | |
print(application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Atualizado de forma correta.