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,6 +16,7 @@ if [[ -z "$OPENWEATHER_APIKEY" ]]; then
|
|||
die "openweathermap api key is not set"
|
||||
fi
|
||||
|
||||
function manual_geo() {
|
||||
if [[ ! -f "$CITY_FILE" ]]; then
|
||||
die "cities.txt is not found"
|
||||
fi
|
||||
|
@ -27,16 +28,6 @@ if [[ -z "$CITY" ]]; then
|
|||
die "city not selected"
|
||||
fi
|
||||
|
||||
set_text_color 43
|
||||
set_bold_text
|
||||
echo -n "Type a title: "
|
||||
reset_text_format
|
||||
read TITLE
|
||||
|
||||
if [[ -z "$TITLE" ]]; then
|
||||
die "title not found"
|
||||
fi
|
||||
|
||||
while true; do
|
||||
set_text_color 43
|
||||
set_bold_text
|
||||
|
@ -58,6 +49,32 @@ while true; do
|
|||
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
|
||||
|
||||
set_text_color 43
|
||||
set_bold_text
|
||||
echo -n "Type a title: "
|
||||
reset_text_format
|
||||
read TITLE
|
||||
|
||||
if [[ -z "$TITLE" ]]; then
|
||||
die "title not found"
|
||||
fi
|
||||
|
||||
RESPONSE=$(curl -s "https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${OPENWEATHER_APIKEY}&units=metric")
|
||||
|
||||
|
@ -85,7 +102,7 @@ if [[ "$weather" -eq 1 ]]; then
|
|||
WEATHER="$(echo "$RESPONSE" | jq -r '.weather[0].description')"
|
||||
TZ="$(calculate_timezone "$(echo "$RESPONSE" | jq -r '.timezone')")"
|
||||
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')"
|
||||
SUNSET="$(date --date='@'"$(echo "$RESPONSE" | jq -r '.sys.sunset')" +'%H:%M')"
|
||||
|
|
|
@ -69,3 +69,11 @@ function generate_random_string() {
|
|||
function checksumm() {
|
||||
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