def hello_world(): is_japan = datetime(year=2015, month=5, day=24) <= datetime.today() <= datetime( year=2015, month=6, day=6) days_left = datetime(year=2015, month=5, day=24) - datetime.today() hours_left = datetime( year=2015, month=5, day=24, hour=11, tzinfo=pytz.timezone('Canada/Eastern')) - datetime.now( tz=pytz.timezone('Canada/Eastern')) japan_time = datetime.now( tz=pytz.timezone('Asia/Tokyo')).strftime('%B %-d, %H:%M') weather = { 'tokyo': get_weather(35.673343, 139.710388), 'kyoto': get_weather(35.0061, 135.76095), } ctx = { 'is_japan': is_japan, 'weather': weather, 'days_left': days_left.days, 'hours_left': (hours_left.seconds // 3600) + (hours_left.days * 24), 'japan_time': japan_time } return render_template('main.html', context=ctx)
def process_request(self): if self.path.startswith("/weather/city/"): # partition returns a 3 part tuple city_id = self.path.partition("/weather/city/")[2] return api.get_weather(city_id) else: return "There is no such endpoint"
def test_get_weather_cache(self): expiration = datetime.utcnow() + timedelta(minutes=15) test = { "name": "test_name", "tz_offset": -1, "temp": { "current": -99, "high": -98, "low": -97 }, "comments": [], "expires": FireBase.date_to_epoch(expiration), "watchers": -96 } result = FireBase.put_weather("test-api-lat", "test-api-lng", test) self.assertTrue(result) data = api.get_weather("test-api-lat", "test-api-lng", test["name"]) self.assertEqual(data["name"], test["name"]) self.assertEqual(data["tz_offset"], test["tz_offset"]) self.assertEqual(data["expires"], test["expires"]) self.assertEqual(data["watchers"], test["watchers"]) self.assertEqual(data["temp"]["current"], test["temp"]["current"]) self.assertEqual(data["temp"]["high"], test["temp"]["high"]) self.assertEqual(data["temp"]["low"], test["temp"]["low"])
def test_get_weather_fresh(self): expiration = datetime.utcnow() - timedelta(minutes=15) test = { "watchers": 0, "expires": FireBase.date_to_epoch(expiration), "key": "388048,-770469", "coords": { "latitude": "38.8048", "longitude": "-77.0469" }, "temp": { "high": "61°F/16°C", "summary": "Overcast", "icon": "cloudy", "current": "48°F/9°C", "low": "44°F/7°C" }, "name": "Alexandria, VA", "tz_offset": "America/New_York" } result = FireBase.put_weather("38.8048", "-77.0469", test) self.assertTrue(result) data = api.get_weather("38.8048", "-77.0469", test["name"]) self.assertNotEqual(test["expires"], data["expires"])
def hello_world(): is_japan = datetime(year=2015, month=5, day=24) <= datetime.today() <= datetime(year=2015, month=6, day=6) days_left = datetime(year=2015, month=5, day=24) - datetime.today() weather = { 'tokyo': get_weather(35.673343, 139.710388), 'kyoto': get_weather(35.0061, 135.76095), } ctx = { 'is_japan': is_japan, 'weather': weather, 'days_left': days_left.days, } return render_template('main.html', context=ctx)
def weather(update, context, *args, **kwargs): context.bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) logger.info(f"Weather... by {update.message.from_user.name}") text = get_weather() if not text: return context.bot.send_message(chat_id=update.message.chat_id, text=text)
def weather(request): name = request.GET.get("name") lat = request.GET.get("lat") lng = request.GET.get("lng") if not name or not lat or not lng: return HttpResponseBadRequest() data = api.get_weather(lat, lng, name) return HttpResponse(json.dumps(data), content_type="application/json")
def hello_world(): is_japan = datetime(year=2015, month=5, day=24) <= datetime.today() <= datetime( year=2015, month=6, day=6) days_left = datetime(year=2015, month=5, day=24) - datetime.today() weather = { 'tokyo': get_weather(35.673343, 139.710388), 'kyoto': get_weather(35.0061, 135.76095), } ctx = { 'is_japan': is_japan, 'weather': weather, 'days_left': days_left.days, } return render_template('main.html', context=ctx)
def hello_world(): is_japan = datetime(year=2015, month=5, day=24) <= datetime.today() <= datetime(year=2015, month=6, day=6) days_left = datetime(year=2015, month=5, day=24) - datetime.today() hours_left = datetime(year=2015, month=5, day=24, hour=11, tzinfo=pytz.timezone('Canada/Eastern')) - datetime.now(tz=pytz.timezone('Canada/Eastern')) japan_time = datetime.now(tz=pytz.timezone('Asia/Tokyo')).strftime('%B %-d, %H:%M') weather = { 'tokyo': get_weather(35.673343, 139.710388), 'kyoto': get_weather(35.0061, 135.76095), } ctx = { 'is_japan': is_japan, 'weather': weather, 'days_left': days_left.days, 'hours_left': (hours_left.seconds // 3600) + (hours_left.days * 24), 'japan_time': japan_time } return render_template('main.html', context=ctx)
def test_get_weather2(self): api.load_config() result = api.get_weather("1234567") self.assertEqual(result['cod'], "404")
def test_get_weather1(self): api.load_config() result = api.get_weather("3448433") self.assertEqual(result['name'], "São Paulo")
def test_get_weather(mocked_fetch): city = "Moscow" res = get_weather(city) assert res is mocked_fetch.return_value mocked_fetch.assert_called_once_with(API_URL, {"city": city})