51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

使用Linux bash脚本获取墨迹云天气数据

使用Linux bash脚本获取墨迹云天气数据 {#%E4%BD%BF%E7%94%A8linux-bash%E8%84%9A%E6%9C%AC%E8%8E%B7%E5%8F%96%E5%A2%A8%E8%BF%B9%E4%BA%91%E5%A4%A9%E6%B0%94%E6%95%B0%E6%8D%AE}

Conkyrc_Weather_Service

#!/bin/bash
weather(){
rm -rf /tmp/URL_LINK
mkdir -p /tmp/URL_LINK/IMG
#-------------------------
# 获取天气数据
#-------------------------
#天气预报页面的地址
URL_LINK='https://tianqi.moji.com/weather/china/fujian/ninghua-county'
URL_LINK_log='/tmp/URL_LINK/URL_LINK.log'
##下载天气预报页面文件
wget -o /dev/null ${URL_LINK} -P /tmp/URL_LINK
#过滤关键字行,显示天气数据
cat /tmp/URL_LINK/${URL_LINK##*/}|grep '今天实况' > ${URL_LINK_log}
#获取空气质量
WGET_URL_LINK(){
cd /tmp/URL_LINK
#下载一张图片 定位 class="wea_weather clearfix" 行 +2行 过滤出图片地址
WGET_IMG=`grep -rEn "class=\"wea_weather clearfix\"" "/tmp/URL_LINK" | sed "s/ .*$//"|grep -P -o "[0-9]+"`
WGET_IMG_A=`expr ${WGET_IMG} + 2`
WGET_IMG_URL=`cat /tmp/URL_LINK/${URL_LINK##*/}|sed -n ${WGET_IMG_A}p|grep -oP "\"\K[^\"]+(?=\")"|grep 'http'`
wget -o /dev/null ${WGET_IMG_URL} -P /tmp/URL_LINK/IMG
mv /tmp/URL_LINK/IMG/*.png /tmp/URL_LINK/IMG/x.png
#查找images/aqi/的行,在这一行下面就有空气质量,把行数过滤出来
A=`grep -rEn "images/aqi/" "/tmp/URL_LINK"| sed "s/ .*$//"| grep -P -o "[0-9]+"`
#做加法 +1行
B=`expr ${A} + 1`
#显示天气质量那一行的字符串,双引号之间的字符串,去除空格
C=`cat ${URL_LINK##*/}|sed -n ${B}p|grep -oP "\"\K[^\"]+(?=\")"|sed 's/ //g'`
echo ${C}
}
#-------------------------
# 数据重组
#-------------------------
WRAP_A_A=":"
WRAP_A_B=","
WRAP_A_C="。"
WRAP_A_D="content=\""
WRAP_B='\n'
sed -i -r "s|${WRAP_A_D}|${WRAP_B}|g" ${URL_LINK_log}
sed -i -r "s|${WRAP_A_A}|${WRAP_B}|g" ${URL_LINK_log}
sed -i -r "s|${WRAP_A_B}|${WRAP_B}|g" ${URL_LINK_log}
sed -i -r "s|${WRAP_A_C}|${WRAP_B}|g" ${URL_LINK_log}
echo -e \
"`cat ${URL_LINK_log} | sed -n 2p`""\n"\
"`WGET_URL_LINK` | "\
"`cat ${URL_LINK_log} | sed -n 3p` | "\
"`cat ${URL_LINK_log} | sed -n 4p`"\
"`cat ${URL_LINK_log} | sed -n 5p` | "\
"`cat ${URL_LINK_log} | sed -n 6p`"\
"`cat ${URL_LINK_log} | sed -n 7p`"|tee -a /tmp/URL_LINK/OK.LOG
jrtqts=`grep -rEn "今日天气提示" "/tmp/URL_LINK" | sed "s/ .*$//"|grep -P -o "[0-9]+"`
jrtqts_a=`expr ${jrtqts} + 1`
cat /tmp/URL_LINK/${URL_LINK##*/}|sed -n ${jrtqts_a}p|cut -d '>' -f2 | cut -d '<' -f1|tee -a /tmp/URL_LINK/OK.LOG
WAIWANG_X=$(curl -s http://www.net.cn/static/customercare/yourip.asp | grep -P -o "[0-9.]+(?=</h2>)")
echo ${WAIWANG_X} |tee -a /tmp/URL_LINK/OK.LOG
}
      weather
#循环执行
while true ; do

      sleep  450s
            weather



`done
`


赞(0)
未经允许不得转载:工具盒子 » 使用Linux bash脚本获取墨迹云天气数据