Exemplo n.º 1
0
 def test_yesterday_with_hour_only(self):
     now = datetime.now()
     yesterday = date.today() + timedelta(days=-1)
     result = timestamps.yesterday(6)
     expected = datetime(yesterday.year, yesterday.month, yesterday.day, 6,
                         now.minute, 0)
     self.assertEqual(expected, result)
 def test_yesterday_with_hour_and_minute(self):
     yesterday = date.today() + timedelta(days=-1)
     result = timestamps.yesterday(18, 56)
     expected = datetime(yesterday.year, yesterday.month, yesterday.day, 18,
                         56, 0, 0, timezone.utc)
     self.assertEqual(expected, result)
     self.is_timezone_aware(result)
Exemplo n.º 3
0
def forecast(city: str, timestamp: str):
    time_to_start = time.time()
    global programMetrics
    global processing_time_of_the_request_forecast_weather
    programMetrics[2] += 1
    mgr = owm.weather_manager()

    observation = mgr.forecast_at_place(
        city, "3h"
    )  #данной командой стягивается прогноз погоды на ближайшие 5 дней с частотой 3 часа
    if timestamp == "1h":
        timest = timestamps.next_hour()
    elif timestamp == "3h":
        timest = timestamps.next_three_hours()
    elif timestamp == "tomorrow":
        timest = timestamps.tomorrow()
    elif timestamp == "yesterday":
        timest = timestamps.yesterday()
    else:
        timest = timestamps.now()
    w = observation.get_weather_at(timest)
    temp = w.temperature('celsius')['temp']
    #вывод в консоль
    print(" request: " + city + "\ttime: " + str(timest) + "\t" +
          w.detailed_status + "\t" + str(temp))
    processing_time_of_the_request_forecast_weather.append(time.time() -
                                                           time_to_start)
    return json.dumps({
        "city": city,
        "unit": "celsius",
        "temperature": temp,
        "id_service": my_id
    })
 def test_yesterday(self):
     now = datetime.now(timezone.utc)
     yesterday = date.today() + timedelta(days=-1)
     result = timestamps.yesterday()
     expected = datetime(yesterday.year, yesterday.month, yesterday.day,
                         now.hour, now.minute, 0, 0, timezone.utc)
     self.assertEqual(expected, result)
     self.is_timezone_aware(result)
Exemplo n.º 5
0
def forecast(city: str, timestamp: str):
    mgr = owm.weather_manager()

    observation = mgr.forecast_at_place(
        city, "3h"
    )  #данной командой стягивается прогноз погоды на ближайшие 5 дней с частотой 3 часа
    if timestamp == "1h":
        time = timestamps.next_hour()
    elif timestamp == "3h":
        time = timestamps.next_three_hours()
    elif timestamp == "tomorrow":
        time = timestamps.tomorrow()
    elif timestamp == "yesterday":
        time = timestamps.yesterday()
    else:
        time = timestamps.now()
    w = observation.get_weather_at(time)
    temp = w.temperature('celsius')['temp']
    #вывод в консоль
    print(" request: " + city + "\ttime: " + str(time) + "\t" +
          w.detailed_status + "\t" + str(temp))
    return json.dumps({"city": city, "unit": "celsius", "temperature": temp})