Last active
March 12, 2020 14:56
-
-
Save kernelhcy/fa6eff3cfd1bfee77bef96c90fc513f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
URL="https://www.zq12369.com/" | |
DATA=`curl --noproxy "*" -s $URL` | |
FORECAST_DATA=`echo $DATA | pup 'div[class="forecast"] json{}'` | |
AQI_DATA=`echo $DATA | pup 'div[class="aqidetail"] json{}' | jq '.[0].children'` | |
curl -s 'https://www.zq12369.com/' | pup 'div[class="aqibg aqibanner1"]' | pup 'div[class="aqi"] json{}' | jq -cMr '.[0].text' | |
function extractAqiDetail() | |
{ | |
echo $1 | jq -cMr ".[$2].children[1].text" | |
} | |
function extractAqiForecastDate() | |
{ | |
local data=`echo "$FORECAST_DATA" | jq ".[$1]"` | |
echo $data | jq -cMr '.children[0].children[0].text' | |
} | |
function extractAqiForecastAqi() | |
{ | |
local data=`echo "$FORECAST_DATA" | jq ".[$1]"` | |
echo $data | jq -cMr '.children[0].children[1].children[1].text' | |
} | |
function extractAqiForecastF() | |
{ | |
local data=`echo "$FORECAST_DATA" | jq ".[$1]"` | |
echo $data | jq -cMr '.children[2].children[0].text' | |
} | |
echo -e "PM2.5: \t`extractAqiDetail "$AQI_DATA" '1'`" | |
echo -e "PM10: \t`extractAqiDetail "$AQI_DATA" '2'`" | |
echo -e "SO2: \t`extractAqiDetail "$AQI_DATA" '3'`" | |
echo -e "NO2: \t`extractAqiDetail "$AQI_DATA" '4'`" | |
echo -e "CO: \t`extractAqiDetail "$AQI_DATA" '5'`" | |
echo -e "O3: \t`extractAqiDetail "$AQI_DATA" '6'`" | |
echo "`extractAqiForecastDate '0'` `extractAqiForecastAqi '0'` `extractAqiForecastF '0'`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment