Skip to content

Commit

Permalink
Implement parse_tags_js with jq
Browse files Browse the repository at this point in the history
  • Loading branch information
sscscc committed Jan 22, 2024
1 parent b3f5d77 commit 76f38cb
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
one_year_ago=$(date -d "1 year ago" +%s)
parse_tags_js() {
is_empty=true
local date_names=($(grep -oP '(?<="last_updated":").+?(?=")|(?<="name":").+?(?=")' <(echo "$tags_js")))
for ((i=0; i<${#date_names[@]}/2; i++)); do
date=$(date -d "${date_names[2*i]}" +%s)
name=${date_names[2*i+1]}
next_page=$(jq -r '.next' <(echo "$tags_js"))
for result in $(jq -c '.results[]' <(echo "$tags_js")); do
date=$(date -d "$(jq -r '.last_updated' <(echo "$result"))" +%s)
name=$(jq -r '.name' <(echo "$result"))
if (( date > one_year_ago )); then
echo "$name"
is_empty=false
fi
fi
done
}
docker-tags(){
Expand All @@ -21,11 +21,8 @@ docker-tags(){
return 1
fi
parse_tags_js
while next_page=$(grep -oP '(?<="next":").+?(?=")' <(echo "$tags_js") | sed 's/\\u0026/\&/' | xargs)
while [[ -n "$next_page" && "$next_page" != "null" && $is_empty == false ]]
do
if [[ -z "$next_page" || "$next_page" == "null" || $is_empty == true ]]; then
break
fi
tags_js=$(curl -sSL "$next_page")
if [ $? -ne 0 ]; then
echo "curl $next_page failed" >&2
Expand Down

0 comments on commit 76f38cb

Please sign in to comment.