예제 #1
0
def location(update, context):
    lat = update.message.location.latitude
    lon = update.message.location.longitude
    forecasts = get_forecasts(lat, lon)
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=forecasts,
                             reply_markup=ReplyKeyboardRemove())
예제 #2
0
def location(bot, update):
    lat = update.message.location.latitude
    lon = update.message.location.longitude
    forecasts = get_forecasts(lat, lon)
    bot.send_message(chat_id=update.message.chat_id,
                     text=forecasts,
                     reply_markup=ReplyKeyboardRemove())
예제 #3
0
def get_forecasts_panel(
        images: Icons, fonts: Fonts,
        config: SectionProxy) -> tuple[Image.Image, tuple[str, str]]:
    logger = logging.getLogger(__name__)
    logger.info('Generating forecast panel')
    icon_width = config.getint('ICON_WIDTH')
    count = 7
    x_size = 1872
    y_size = 800
    (forecasts, first_position,
     first_position_name) = get_forecasts(config.get('FMI_LOCATION'), count, 6)
    logger.info('Received data: %s', repr(forecasts))

    dates = sorted(forecasts.keys())
    image = Image.new('L', (x_size, y_size), 0xff)
    draw = ImageDraw.Draw(image)

    utils.draw_title(draw, fonts['font_sm'], 'FORECAST', first_position_name,
                     fonts['font_xxs'])

    data_y_base = 100

    for date, i in zip(dates, range(len(dates))):
        is_daylight = get_is_daylight(first_position, date)
        data = forecasts[date]
        date_local = utils.utc_datetime_string_to_local_datetime(date)
        date_formatted = date_local.strftime('%-H:%M')
        x_step = x_size // count
        x_base = x_step // 2

        # Time
        draw.text((x_base + i * x_step, data_y_base + 10),
                  date_formatted,
                  font=(fonts['font_sm'] if date_formatted != "15:00" else
                        fonts['font_sm_bold']),
                  fill=0,
                  anchor='mt')

        # Weather icon
        icon_position = (x_base + i * x_step -
                         config.getint('ICON_WIDTH') // 2, data_y_base + 80)
        weather_icon = icons.get_scaled_image(
            get_forecats_weather_icon(data['WeatherSymbol3'], is_daylight,
                                      images, fonts, config), icon_width)
        image.paste(weather_icon, icon_position, weather_icon)

        # Warning icon
        if (utils.show_temperatur_warning_icon(data["Temperature"], date_local,
                                               config)):
            warning_icon = icons.get_scaled_image(images['misc']['warning'],
                                                  50)
            image.paste(warning_icon,
                        (icon_position[0] + weather_icon.width -
                         2 * warning_icon.width // 3, icon_position[1] +
                         weather_icon.height - 2 * warning_icon.height // 3),
                        warning_icon)

        # Temperature
        utils.draw_quantity(draw, (x_base + i * x_step, data_y_base + 350),
                            str(round(data["Temperature"])), '°C', fonts)
        # Wind speed
        utils.draw_quantity(draw, (x_base + i * x_step, data_y_base + 420),
                            str(round(data["WindSpeedMS"])), 'm/s', fonts)

        # Cloud cover
        cloud_cover_raw = data["TotalCloudCover"]
        cloud_cover = math.nan if math.isnan(
            cloud_cover_raw) else cloud_cover_raw / 100 * 8
        cloud_cover_icon = icons.get_scaled_image(
            utils.get_cloud_cover_icon(cloud_cover, images, fonts, config),
            160)
        image.paste(cloud_cover_icon,
                    (x_base + i * x_step - cloud_cover_icon.width // 2,
                     data_y_base + 440), cloud_cover_icon)

        # Wind direction
        wind_image = icons.get_scaled_image(images['misc']['wind_icon'], 160)
        wind_image_rot = wind_image.rotate(-data['WindDirection'] + 180,
                                           fillcolor=0xff,
                                           resample=Image.BICUBIC)
        image.paste(wind_image_rot,
                    (x_base + i * x_step - wind_image_rot.width // 2,
                     data_y_base + 440), wind_image_rot)

    # Borders
    if (config.getboolean('DRAW_PANEL_BORDERS')):
        draw.polygon([(0, 0), (x_size - 1, 0), (x_size - 1, y_size - 1),
                      (0, y_size - 1), (0, 0)])

    return (image, first_position)
예제 #4
0
Plot the forecasted temperatures of Miami in Celsius. You'll need to use the "<a href='#'>create empty list</a>" and "<a href='#'>append</a>" blocks to create a new list of Celsius temperatures from the forecasted temperatures in Blacksburg, and then plot these new temperatures against the old ones. 
#####
import weather
import matplotlib.pyplot as plt


celsius_temperatures = []
for t in weather.get_forecasts("Miami, FL"):
    celsius = (t - 32) / 1.8
    celsius_temperatures.append(celsius)
plt.plot(celsius_temperatures)
plt.title("Temperatures in Miami")
plt.show()
#####
def on_run(code, output, properties):
    return True
예제 #5
0
Print the name of the state that had the highest violent crime rate in 1995.
#####
import matplotlib.pyplot as plt
import weather


plt.plot(weather.get_forecasts("Blacksburg, VA"))
plt.show()
#####
def on_run(code, output, properties):
    if 'crime.get_by_year' not in code:
        return "You'll need to use the 'get by year' block!"
    elif 'violent' not in code:
        return "You need to get the violent crime rate."
    elif 'state' not in code:
        return "You also need to store the state name while you iterate!"
    elif 'if' not in code:
        return "You will need some decision in your code. This is similar to the problems we did before where we found the maximum."
    elif output.strip() == 'District of Columbia':
        return true
    else:
        return 'You can do it!'