update
This commit is contained in:
1 parent
8ab9cc1e1f
commit
7006bfdfb3
29 files changed
+2308
-287
No files matched your search
@@ -5,7 +5,7 @@ get() {
|
||||
|
||||
while IFS= read -r line; do
|
||||
echo "$line" | iconv -t UTF-8
|
||||
done <<< "$clip_list"
|
||||
done <<<"$clip_list"
|
||||
}
|
||||
|
||||
copy_by_id() {
|
||||
@@ -14,8 +14,7 @@ copy_by_id() {
|
||||
}
|
||||
|
||||
if [[ "$1" == "--get" ]]; then
|
||||
get
|
||||
get
|
||||
elif [[ "$1" == "--copy-by-id" ]]; then
|
||||
{ copy_by_id "$2"; }
|
||||
{ copy_by_id "$2"; }
|
||||
fi
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
KEY=$2
|
||||
ID=$3
|
||||
UNIT="metric"
|
||||
|
||||
cache_dir=$HOME/.cache/ags/weather
|
||||
cache_file="$cache_dir/weather_cache.json"
|
||||
cache_max_age=900
|
||||
mkdir -p $cache_dir
|
||||
|
||||
get_weather_data() {
|
||||
current_time=$(date +%s)
|
||||
cache_key=$(echo "$KEY $ID $UNIT" | md5sum | awk '{ print $1 }')
|
||||
|
||||
if [[ -f "$cache_file" ]]; then
|
||||
cached_key=$(cat "$cache_file" | jq -r '.cache_key')
|
||||
last_modified=$(stat -c %Y "$cache_file")
|
||||
|
||||
if [[ "$cached_key" == "$cache_key" && $((current_time - last_modified)) < $cache_max_age ]]; then
|
||||
cat "$cache_file" | jq -r '.data'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$KEY&id=$ID&units=$UNIT")
|
||||
echo "{ \"cache_key\": \"$cache_key\", \"data\": $weather }" >"$cache_file"
|
||||
cat "$cache_file" | jq -r '.data'
|
||||
}
|
||||
|
||||
if [[ "$1" == "weather" ]]; then
|
||||
get_weather_data
|
||||
fi
|
||||
Reference in new issue
Block a user