예제 #1
0
 def test_parse(self):
     forecast_ = Forecast()
     with Scraper() as scraper_:
         soup = scraper_.scrape(url=url)
     formatted_forecasts = forecast_.parse(station_name='Grindavík',
                                           soup=soup)
     self.assertIsNotNone(formatted_forecasts)
예제 #2
0
def weather():
    day, night, tomorrow = Forecast.current()
    return json.dumps({
        'day': day.to_json(),
        'night': night.to_json(),
        'tomorrow': tomorrow.to_json()
    })
예제 #3
0
    async def main(future):
        async with aiohttp.ClientSession() as session:

            # get location data from api
            fetch_locations = [fetch(session, url) for url in location_queries]
            location_data = await asyncio.gather(*fetch_locations)

            # get weather data based on woeids
            weather_queries = []
            for row in location_data:
                woeid = str(row[0]['woeid'])
                weather_query = f'https://www.metaweather.com/api/location/{woeid}/'
                weather_queries.append(weather_query)

            fetch_weathers = [fetch(session, url) for url in weather_queries]
            weather_data = await asyncio.gather(*fetch_weathers)

            # create json object from locations and weather data
            results = {}
            for location, city in zip(locations, weather_data):
                results[location] = []
                weather = city['consolidated_weather']
                for day in weather:
                    date = day['applicable_date']
                    temp = day['the_temp']
                    description = day['weather_state_name']
                    forecast = Forecast(date, temp, description)
                    results[location].append(forecast)

            return results
예제 #4
0
def save(rest, weather):
    #save method the restaurant that the user book-marked.
    rest = Restaurant("name", "address", 1) 
    row = conn.execute('insert into travel_tip(name, address, rating) values (?, ?, ?)', (rest.name, rest.address, rest.rating ))

    weather = Forecast("description", "temp")
    row = conn.execute('insert into weather(description, temp) values (?, ?)', (weather.description, weather.temp))
    conn.commit()
    return row.rowcount
예제 #5
0
 def test_instance(self):
     forecast_ = Forecast()
     self.assertIsInstance(forecast_, Forecast)
예제 #6
0
 def load_forecasts(self):
     forecast = Forecast(self.lat, self.lon)
     self.hourly_forecast = json.dumps(forecast.load_hourly_forecast())
예제 #7
0
def test_weather_forecast_with_clouds_sky():
    with open("tests/data/forecast.json") as opened_file:
        forecast_dict = json.loads(opened_file.read())
    forecast = Forecast(None, None, forecast_dict)
    forecast_dict = forecast.load_hourly_forecast()
    assert forecast_dict[1528092000] == "clouds"
예제 #8
0
def test_weather_forecast_for_hour():
    with open("tests/data/forecast.json") as opened_file:
        forecast_dict = json.loads(opened_file.read())
    forecast = Forecast(None, None, forecast_dict)
    assert forecast.for_timestamp(1528103800) == "rain"