python天气_如何在python中创建天气警报系统

本文介绍了如何利用Python创建一个天气警报系统,通过翻译自towardsdatascience的文章,详细讲解了实现过程。
摘要由CSDN通过智能技术生成

python天气

By reading this piece, you will learn to create a weather alert system in Python that will send an email notification to multiple recipients when it forecasts that the sky will rain/snow in the next few hours. The email notification contains additional information such as the forecast-ed temperature and humidity.

通过阅读本文,您将学习如何使用Python创建天气警报系统,该系统将在接下来的几个小时预测天空会下雨/下雪时向多个收件人发送电子邮件通知。 电子邮件通知包含其他信息,例如预测的温度和湿度。

There are 4 sections in this tutorial:

本教程分为4个部分:

  1. Setup

    建立
  2. Implementation

    实作
  3. Result

    结果
  4. Conclusion

    结论

Let’s proceed to the next section.

让我们继续下一节。

1.设定 (1. Setup)

天气API(Weather API)

I am going to use ClimaCell’s weather API in getting the forecasted weather data. It provides quite a number of useful and accurate data depends on your needs.

我将使用ClimaCell的天气API来获取天气预报数据。 它根据您的需求提供了大量有用且准确的数据。

At the time of this writing, it covers historical station data up to 4 weeks back as well as daily forecast data up to 15 days ahead. Besides, you can easily implement it as the official documentation provides references for 4 different computer languages:

在撰写本文时,它涵盖了长达4周的历史台站数据以及长达15天的每日天气预报数据。 此外,您可以轻松实现它,因为官方文档提供了4种不同计算机语言的参考:

  • JavaScript

    JavaScript
  • Ruby

    Ruby
  • Node

    节点
  • Python

    Python

Once you have signed up for it, you will be placed under free tier which allow you to make 1000 call per day and 100 per hour. It should be more than enough for our use case.

注册后,您将被置于免费套餐下,您可以每天拨打1000次,每小时拨打100次。 对于我们的用例来说,它应该绰绰有余。

Head over to the sign up and and register a new account. Once you are done, you should see the following dashboard which outlines the plan details and your call activity.

前往注册并注册一个新帐户。 完成后,您将看到以下仪表盘,其中概述了计划详细信息和您的通话活动。

Image for post
Image by Author
图片作者

Take note of the API key as we are going to use it in our code later on.

请注意API密钥,因为稍后我们将在代码中使用它。

电子邮件设定 (Email Configuration)

I am going to use a personal Gmail account to send the email to myself via SMTP. In order to use it, you need to change the configuration in the account setting and turn on the Less secure app access.

我将使用个人Gmail帐户通过SMTP将电子邮件发送给自己。 为了使用它,您需要在帐户设置中更改配置,然后打开Less secure app access

Head over to the account setting and click on the security menu.

转到帐户设置,然后单击安全菜单。

Image for post
Image by Author
图片作者

Turn on the Less secure app access as follow

如下打开“ Less secure app access

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值