WeIO weather forecast

tempCarte

If you need weather forecast for Swiss, France and Belgium there is good site for that, www.prevision-meteo.ch
I was playing around with WeIO to get and parse these data. This is more example of how we can get and interpret some data from Web API using json format than complete projet.

Here is main.py program

from weioLib.weio import *
import json, os, urllib2

dataFile = "www/flash/meteo/meteo.txt"
city = "paris"

def setup():
    attach.process(myProcess)
    
def myProcess():
    print "Getting data from the server"
    data = getData(city)
    print "Saving to file"
    f = open(dataFile, "w")
    f.write(beautify(data))
    f.close()
    print "File saved", dataFile
            
def beautify(data):
    return json.dumps(data, indent=4, sort_keys=True)

def getData(city):
        url = "http://www.prevision-meteo.ch/services/json/" + city
        req = urllib2.Request(url)
        response = urllib2.urlopen(req)
        the_page = response.read()
        return json.loads(the_page)  

 

uros posted this.

07, April

About uros

Uros is co-author of WeIO project

Did this answer your question? If not, send us a message?