Skip to content

Instantly share code, notes, and snippets.

@framp
Last active May 29, 2023 17:49
Show Gist options
  • Save framp/48f990430d473a83788f790176e0a6e5 to your computer and use it in GitHub Desktop.
Save framp/48f990430d473a83788f790176e0a6e5 to your computer and use it in GitHub Desktop.
Get weather info for Paphos, Cyprus
#!/bin/bash
SEA=$(curl 'https://seatemperature.info/paphos-water-temperature.html' \
-H 'authority: seatemperature.info' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: en-GB,en;q=0.9,en-US;q=0.8,it;q=0.7,es;q=0.6' \
-H 'cache-control: no-cache' \
-H 'cookie: adviv=1' \
-H 'dnt: 1' \
-H 'pragma: no-cache' \
-H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
--compressed 2>/dev/null | grep "today temp" | awk -F'[<>]' '/today temp/{print $13}')
curl 'https://www.kitasweather.com/paphos/' \
-H 'authority: www.kitasweather.com' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: en-GB,en;q=0.9,en-US;q=0.8,it;q=0.7,es;q=0.6' \
-H 'cache-control: no-cache' \
-H 'cookie: __gpi=UID=00000bb5326acb6b:T=1676298814:RT=1676298814:S=ALNI_MaFp8-g8XKlm-C1bNzMphMj7695wQ; moove_gdpr_popup=%7B%22strict%22%3A%221%22%2C%22thirdparty%22%3A%221%22%2C%22advanced%22%3A%221%22%7D' \
-H 'dnt: 1' \
-H 'pragma: no-cache' \
-H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
--compressed 2>/dev/null >/tmp/weather-paphos
function get_info () {
local output_array=()
local lines=$(cat /tmp/weather-paphos | grep '>'"$1" -A10 | tail -10 | sed -n 's/^.*>\(.*\)<.*$/\1/p' | sed 's/&#8211;//' | sed 's/℃//')
while IFS= read -r line; do
output_array+=("$line")
done <<< "$lines"
printf '%s\n' "${output_array[@]}"
}
TMAX=($(get_info "T.max"))
TMIN=($(get_info "T.min"))
RAIN_AMOUNT=($(get_info "Precipitation"))
RAIN_AM=($(get_info "Ch. of Rain (am)"))
RAIN_PM=($(get_info "Ch. of Rain (pm)"))
RAIN_NIGHT=($(get_info "Ch. of Rain (night)"))
WIND=($(get_info "Wind p.m (Bft)"))
SUNSHINE=($(get_info "Hrs of Sunshine"))
UV=($(get_info "UV Index"))
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
BLUE='\033[0;34m'
echo -e "${YELLOW}TODAY${NC}":
echo -e Air temperature is ${GREEN}${TMIN[0]}-${TMAX[0]}°C${NC}
echo -e Sea water temperature is ${GREEN}${SEA}°C${NC}
echo -en Chance of rain is ${BLUE}${RAIN_AM[0]}${NC} \(AM\), ${BLUE}${RAIN_PM[0]}${NC} \(PM\), ${BLUE}${RAIN_NIGHT[0]}${NC} \(Night\)
if [ -n "$RAIN_AMOUNT" ]; then
echo -en " for a total of ${BLUE}$RAIN_AMOUNT${NC}"
fi
echo
echo -e Wind will blow ${BLUE}${WIND[0]} ${WIND[1]}${NC}
echo -e You\'ll enjoy ${RED}${SUNSHINE[0]}${NC} hours of sunshine
echo -e The UV index is ${RED}${UV[0]}${NC}
rm /tmp/weather-paphos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment