20250113.1736787084
This commit is contained in:
parent
cfce6c21e1
commit
ba47a5917e
3 changed files with 55 additions and 30 deletions
Binary file not shown.
|
@ -16,15 +16,54 @@ if [[ -z "$OPENWEATHER_APIKEY" ]]; then
|
||||||
die "openweathermap api key is not set"
|
die "openweathermap api key is not set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$CITY_FILE" ]]; then
|
function manual_geo() {
|
||||||
die "cities.txt is not found"
|
if [[ ! -f "$CITY_FILE" ]]; then
|
||||||
fi
|
die "cities.txt is not found"
|
||||||
|
fi
|
||||||
|
|
||||||
CITY=$(cat "$CITY_FILE" | fzf --prompt="Type a city: ")
|
CITY=$(cat "$CITY_FILE" | fzf --prompt="Type a city: ")
|
||||||
|
|
||||||
# Проверяем, выбран ли город
|
# Проверяем, выбран ли город
|
||||||
if [[ -z "$CITY" ]]; then
|
if [[ -z "$CITY" ]]; then
|
||||||
die "city not selected"
|
die "city not selected"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
set_text_color 43
|
||||||
|
set_bold_text
|
||||||
|
echo -n "Type a geo: "
|
||||||
|
reset_text_format
|
||||||
|
read GEO
|
||||||
|
|
||||||
|
# if a string is empty then skip it
|
||||||
|
if [[ -z "$GEO" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$GEO" =~ ^-?[0-9]+\.[0-9]+,-?[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
set_text_color 1
|
||||||
|
set_bold_text
|
||||||
|
echo "Wrong geo format (lat and lon 52.18969496420507,20.90814238187223)"
|
||||||
|
reset_text_format
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
connection=$(check_connection)
|
||||||
|
if [[ "$connection" = 0 ]]; then
|
||||||
|
manual_geo
|
||||||
|
else
|
||||||
|
http_code=$(curl -H "Authorization: Basic ${GEO_SERVER_AUTH}" -s -o /dev/null -w "%{http_code}" "${GEO_SERVER_URL}?action=diary&type=get_geo")
|
||||||
|
echo "$http_code"
|
||||||
|
if [ "$http_code" -ne 200 ]; then
|
||||||
|
echo "Connection problem...\n"
|
||||||
|
manual_geo
|
||||||
|
fi
|
||||||
|
location=$(curl -H "Authorization: Basic ${GEO_SERVER_AUTH}" -s "${GEO_SERVER_URL}?action=diary&type=get_geo")
|
||||||
|
IFS=":" read -r lat lon CITY country timestamp <<<"$location"
|
||||||
|
GEO="$lat,$lon"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set_text_color 43
|
set_text_color 43
|
||||||
|
@ -37,28 +76,6 @@ if [[ -z "$TITLE" ]]; then
|
||||||
die "title not found"
|
die "title not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true; do
|
|
||||||
set_text_color 43
|
|
||||||
set_bold_text
|
|
||||||
echo -n "Type a geo: "
|
|
||||||
reset_text_format
|
|
||||||
read GEO
|
|
||||||
|
|
||||||
# if a string is empty then skip it
|
|
||||||
if [[ -z "$GEO" ]]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$GEO" =~ ^-?[0-9]+\.[0-9]+,-?[0-9]+\.[0-9]+$ ]]; then
|
|
||||||
break
|
|
||||||
else
|
|
||||||
set_text_color 1
|
|
||||||
set_bold_text
|
|
||||||
echo "Wrong geo format (lat and lon 52.18969496420507,20.90814238187223)"
|
|
||||||
reset_text_format
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
RESPONSE=$(curl -s "https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${OPENWEATHER_APIKEY}&units=metric")
|
RESPONSE=$(curl -s "https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${OPENWEATHER_APIKEY}&units=metric")
|
||||||
|
|
||||||
if [[ "$(echo "$RESPONSE" | jq '.cod')" != "200" ]]; then
|
if [[ "$(echo "$RESPONSE" | jq '.cod')" != "200" ]]; then
|
||||||
|
@ -85,7 +102,7 @@ if [[ "$weather" -eq 1 ]]; then
|
||||||
WEATHER="$(echo "$RESPONSE" | jq -r '.weather[0].description')"
|
WEATHER="$(echo "$RESPONSE" | jq -r '.weather[0].description')"
|
||||||
TZ="$(calculate_timezone "$(echo "$RESPONSE" | jq -r '.timezone')")"
|
TZ="$(calculate_timezone "$(echo "$RESPONSE" | jq -r '.timezone')")"
|
||||||
WEATHER_ICON="$(echo "$RESPONSE" | jq -r '.weather[0].icon')"
|
WEATHER_ICON="$(echo "$RESPONSE" | jq -r '.weather[0].icon')"
|
||||||
TEMPERATURES="🌡️ $(round $(echo "$RESPONSE" | jq -r '.main.temp')) ($(round $(echo "$RESPONSE" | jq -r '.main.feels_like')))"
|
TEMPERATURES="🌡️ $(round $(echo "$RESPONSE" | jq -r '.main.temp'))C ($(round $(echo "$RESPONSE" | jq -r '.main.feels_like'))C)"
|
||||||
|
|
||||||
SUNRISE="$(date --date='@'"$(echo "$RESPONSE" | jq -r '.sys.sunrise')" +'%H:%M')"
|
SUNRISE="$(date --date='@'"$(echo "$RESPONSE" | jq -r '.sys.sunrise')" +'%H:%M')"
|
||||||
SUNSET="$(date --date='@'"$(echo "$RESPONSE" | jq -r '.sys.sunset')" +'%H:%M')"
|
SUNSET="$(date --date='@'"$(echo "$RESPONSE" | jq -r '.sys.sunset')" +'%H:%M')"
|
||||||
|
|
|
@ -69,3 +69,11 @@ function generate_random_string() {
|
||||||
function checksumm() {
|
function checksumm() {
|
||||||
echo $(sha256sum "${1:?}" | awk '{print $1}')
|
echo $(sha256sum "${1:?}" | awk '{print $1}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_connection() {
|
||||||
|
if ping -c 1 google.com &>/dev/null; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue