Skip to content

Instantly share code, notes, and snippets.

@Wanhenri
Last active February 14, 2020 12:49
Show Gist options
  • Save Wanhenri/abd2ca4e4fd6a08ff4eb64e1c2d22299 to your computer and use it in GitHub Desktop.
Save Wanhenri/abd2ca4e4fd6a08ff4eb64e1c2d22299 to your computer and use it in GitHub Desktop.
read txt and convert for json file
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)
@Wanhenri
Copy link
Author

Atualizado de forma correta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment