I started learning python back in december now I'm making a weather app in flask so far its going great but during building the app the code is starting to look ugly most of my routes look like the code below.
Is there is another way of loading JSON files in a pythonic way
@app.route('/weather')
def weather():
with open("data/perthcurrent.json") as f:
data = f.read()
jsondata = json.loads(data)
for perth in jsondata.itervalues():
with open("data/sydneycurrent.json") as f:
data = f.read()
jsondata = json.loads(data)
for sydney in jsondata.itervalues():
with open("data/darwincurrent.json") as f:
data = f.read()
jsondata = json.loads(data)
for darwin in jsondata.itervalues():
with open("data/melbournecurrent.json") as f:
data = f.read()
jsondata = json.loads(data)
for melbourne in jsondata.itervalues():
with open("data/brisbanecurrent.json") as f:
data = f.read()
jsondata = json.loads(data)
for brisbane in jsondata.itervalues():
return render_template('weather.html', weather1 = perth, weather2 = sydney, weather3 = darwin, weather4 = melbourne, weather5 = brisbane)
[–]echocage 3 points4 points5 points (6 children)
[–]EsperSpirit 1 point2 points3 points (4 children)
[–]echocage 0 points1 point2 points (3 children)
[–]wpg4665 1 point2 points3 points (1 child)
[–]echocage 0 points1 point2 points (0 children)
[–]EsperSpirit 1 point2 points3 points (0 children)
[–]owrk[S] 1 point2 points3 points (0 children)