Code Monkey home page Code Monkey logo

smsweather's Introduction

SmsWeather

每天发送一封包含天气预报信息的简短邮件到某个运营商邮箱,进而实现天气预报短信的效果。

程序使用的是百度地图提供的天气 API,据称每天提供 5000 次调用。我想用着代码中附带的 这个应该就够用了。

配置

程序必须经过(有点繁琐的)配置才能使用。所有可配置项都放在了 config.py 文件中:

  • location:需要预报的地理位置,例如“海淀”。可以通过 [这种格式] (http://api.map.baidu.com/telematics/v3/weather?location=海淀&output=json&ak=2b7e46d89c9064014ff84587b8c6010a) 的 URL 在浏览器中验证给定的地方是否合法
  • api_key:(可选)使用自己的百度账号到 [这里] (http://lbsyun.baidu.com/index.php?title=car/api/weather) 申请天气 API 的使用权限,得到相应的 API Key
  • to_mail_addr:接收人邮箱地址。一般为运营商邮箱,如移动的 139 邮箱
  • from_mail_addr:发送人邮箱地址,任意邮箱提供商均可
  • mail_smtp_server:发送人邮箱 SMTP 服务器地址
  • mail_smtp_usr:发送人用来登录 SMTP 服务器的用户名
  • mail_smtp_psw:发送人用来登录 SMTP 服务器的密码
  • mail_sender_desc:邮件中“发送人”的描述
  • mail_subject:邮件主题

定时执行

在 Linux 下可以使用 cron 来实现定点执行这个脚本:

* 18 * * * /home/tmpusr/scripts/smsweather/weather.py > /tmp/smsweather.log 2>&1

上述指令实现了每天 18 点时自动执行这个脚本。

(用法:在终端中输入crontab -e打开编辑器,添加上述指令即可)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.