def get_weather():
    the_print("try to load weather.")
    import WeatherParser
    weather_list = WeatherParser.get_weather()
    # print weather_list
    the_print("weather loaded.")
    return json.dumps(weather_list)
Exemplo n.º 2
0
def index():
    if request.method == 'POST':
        data = request.form['city_name']
        try:
            WeatherGather.send_API(data)
            cityName, temperature, humidity, wind = WeatherParser.read_JSON()
            hat, top, pants, shoes = OutfitFinder.HC(float(temperature),
                                                     float(humidity),
                                                     float(wind))
            cap = hat
            haina = top
            incaltaminte = shoes
            pantaloni = pants
            hat = csvReader.find_image(hat)
            top = csvReader.find_image(top)
            pants = csvReader.find_image(pants)
            shoes = csvReader.find_image(shoes)
        except:
            cityName = ""
            data = ""
            temperature = ""
            humidity = ""
            wind = ""
            hat = ""
            top = ""
            pants = ""
            shoes = ""
            cap = ""
            haina = ""
            pantaloni = ""
            incaltaminte = ""
    else:
        cityName = ""
        data = ""
        temperature = ""
        humidity = ""
        wind = ""
        hat = ""
        top = ""
        pants = ""
        shoes = ""
        cap = ""
        haina = ""
        pantaloni = ""
        incaltaminte = ""
    return render_template('index.html',
                           city=cityName,
                           temp=str(temperature) + "°C",
                           umiditate=str(humidity) + "%",
                           wind=str(wind) + " km/h",
                           hat=hat,
                           top=top,
                           pants=pants,
                           shoes=shoes,
                           cap=cap,
                           incaltaminte=incaltaminte,
                           pantaloni=pantaloni,
                           haina=haina)
Exemplo n.º 3
0
def fetch_xml_data(data):
    """
        this pulls the data from twisted once it has fetched the XML data
    """

    xml_root = et.fromstring(data)

    try:
        #Attempt to parse the xml data into English instead of short tags.
        wp = WeatherParser.weather_parser(xml_root)
        #For some reasons that I have yet to learn. Twisted likes to get stuck in a loop if there's an error in the code
        # unless exceptions are caught outside. Hence the current broad catch.
    except:
        traceback.print_exc()

    #done! Close down twisted event loop
    shutdownwebapp()
 def test_weather_parser(self):
     """Test may fail due to change in weather information
     """
     self.assertEqual(WeatherParser.get_weather().__repr__(),
                      "[{'lat': 1.34, 'lng': 103.99, 'weather': 'Mostly Cloudy', 'temperature': '29'}, {'lat': 1.37, 'lng': 103.91, 'weather': 'Partly Cloudy', 'temperature': '27'}, {'lat': 1.37, 'lng': 103.69, 'weather': 'Mostly Cloudy', 'temperature': '26'}, {'lat': 1.34, 'lng': 103.84, 'weather': 'Partly Cloudy', 'temperature': '27'}, {'lat': 1.39, 'lng': 103.81, 'weather': 'Mostly Cloudy', 'temperature': '26'}]")