Send weather information using sendemail
Look book raspberry pie, can be found using sendemail send weather information, nothing else, tossing a wave
Get weather data
Here you can use wind weather developer , register and getkey
Into the development of the document, you can use the interface to obtain (free version) conventional weather data
https://free-api.heweather.net/s6/weather/{weather-type}?{parameters}
{weather-type}
Representing different types of weather data, mandatory. Use the following values:
weather-type value | description |
---|---|
now | Live weather |
forecast | 3-10 day forecast |
hourly | Hourly forecast |
lifestyle | Index of living |
{parameters}
Parameters representative of the request, including the required and optional parameters. All requests for the presence of parameter & Chinese or special characters separated values of parameters, the parameters required url encode
parameters value | description | description |
---|---|---|
location | Need to query city or region (latitude and longitude / city name [Pinyin, Chinese characters] / IP, etc.) | required |
only | Multi-language, you can not use this argument, the default is Simplified Chinese | Optional |
unit | Unit selection metric (m) or English (I), default metric units | Optional |
key | User authentication key | Mandatory |
For details, please see the weather and wind on their own API
The API returns a string json data, data needs to be resolved here may be mounted jq
tool
> sudo apt-get install jq -y
The following is the code to obtain weather data
#!/bin/bash
# Weather Data
CITY=hefei
TOKEN=和风KEY
WEATHER=$(curl "https://free-api.heweather.net/s6/weather/lifestyle?location=${CITY}&key=${TOKEN}")
SUGGESTIONS=$(echo ${WEATHER} | jq -r '.HeWeather6[0].lifestyle| values[].txt')
echo ${SUGGESTIONS}
Installation sendemail
It can be used directly apt-get
to install sendemail
, and will likely need to install some dependencies
> sudo apt-get install sendemail -y
> sudo apt-get install libio-socket-ssl-perl libnet-ssleay-perl -y
Send email
#!/bin/bash
#Email Send Test
SERVER="smtp.sina.com:22"
FROM=""
TO=""
SUBJECT="test"
MESSAGE="test_content"
CHARSET="utf-8"
USERNAME=""
PASSWORD=""
sendemail \
-f ${FROM} \
-t ${TO} \
-u ${SUBJECT} \
-s ${SERVER} \
-m ${MESSAGE} \
-xu ${USERNAME} \
-xp ${PASSWORD} \
-v -o message-charset=${CHARSET}
Of each parameter are as follows:
-f: 表示发送者的邮箱
-t: 表示接收者的邮箱
-s: 表示SMTP的服务器的域名或者IP,也可以加端口号 域名:port
-u: 表示邮件主题
-m: 表示的内容
-xu: 表示SMTP验证的用户名(也就是登录邮箱的用户名)
-xp: 表示SMTP验证的密码(也就是登录邮箱的密码)
-cc: 表示抄送
-bcc: 表示暗抄送
-a: 后加文件名,会以附件的形式发送
-o message-charset=utf8 邮件内容的编码
-o message-content-type=html 邮件内容的格式
-o message-file=a.txt 把文件内容以邮件正文发出
Are summarized as follows:
#!/bin/bash
# Weather Data
CITY=hefei
TOKEN=和风KEY
WEATHER=$(curl "https://free-api.heweather.net/s6/weather/lifestyle?location=${CITY}&key=${TOKEN}")
SUGGESTIONS=$(echo ${WEATHER} | jq -r '.HeWeather6[0].lifestyle| values[].txt')
echo ${SUGGESTIONS}
#Email Send
SERVER="smtp.sina.com:22"
FROM=""
TO=""
SUBJECT="天气预报来啦"
MESSAGE=${SUGGESTIONS}
CHARSET="utf-8"
USERNAME=""
PASSWORD=""
sendemail \
-f ${FROM} \
-t ${TO} \
-u ${SUBJECT} \
-s ${SERVER} \
-m ${MESSAGE} \
-xu ${USERNAME} \
-xp ${PASSWORD} \
-v -o message-charset=${CHARSET}