2nd commit
This commit is contained in:
302
select.sh
Executable file
302
select.sh
Executable file
@@ -0,0 +1,302 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#NO_COLOR=1
|
||||
|
||||
# Check if NO_COLOR is set to disable colorization
|
||||
if [ -z "$NO_COLOR" ]; then
|
||||
: "${COLOR_GREEN:=$'\e[32m'}"
|
||||
: "${COLOR_GREEN_BOLD:=$'\e[1;32m'}"
|
||||
: "${COLOR_RED:=$'\e[31m'}"
|
||||
: "${COLOR_RED_BOLD:=$'\e[1;31m'}"
|
||||
: "${COLOR_YELLOW=$'\e[33m'}"
|
||||
: "${COLOR_YELLOW_BOLD:=$'\e[1;33m'}"
|
||||
: "${COLOR_SILVER=$'\e[37m'}"
|
||||
: "${COLOR_LIGHT_GREY=$'\e[249m'}"
|
||||
: "${COLOR_BRIGHT_PURPLE=$'\e[35;1m'}"
|
||||
: "${BOLD:=$'\e[1m'}"
|
||||
: "${ITALIC:=$'\e[3m'}"
|
||||
: "${COLOR_RESET:=$'\e[00m'}"
|
||||
else
|
||||
: "${BOLD:=$'\e[1m'}"
|
||||
: "${COLOR_RESET:=$'\e[00m'}"
|
||||
: "${ITALIC:=$'\e[3m'}"
|
||||
fi
|
||||
|
||||
#api_key=
|
||||
#user_id=
|
||||
|
||||
### Variables for self updating
|
||||
ScriptArgs=( "$@" )
|
||||
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
||||
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
||||
|
||||
dotenv () {
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || { echo -e "${red}\nNo .env file found ! No API key for Flickr.'.${reset}"; exit 1; }
|
||||
set +a
|
||||
}
|
||||
|
||||
dotenv
|
||||
|
||||
source "$ScriptWorkDir/functions.sh"
|
||||
|
||||
: <<'END_COMMENT2'
|
||||
TABLE photos (
|
||||
PhotoID VARCHAR(16) PRIMARY KEY,
|
||||
Title VARCHAR(50),
|
||||
Description VARCHAR(100),
|
||||
Posted VARCHAR(16),
|
||||
Taken VARCHAR(16),
|
||||
View INT,
|
||||
Favorites INT,
|
||||
Comments INT,
|
||||
Tags VARCHAR(300),
|
||||
Url VARCHAR(75),
|
||||
AlbumID VARCHAR(100),
|
||||
GroupID VARCHAR(150)
|
||||
)
|
||||
|
||||
TABLE groups (
|
||||
GroupID VARCHAR(16) PRIMARY KEY,
|
||||
GroupTitle VARCHAR(75),
|
||||
GroupUrl VARCHAR(50)
|
||||
)
|
||||
|
||||
TABLE albums (
|
||||
AlbumID INT PRIMARY KEY,
|
||||
AlbumTitle VARCHAR(50) UNIQUE
|
||||
)
|
||||
END_COMMENT2
|
||||
|
||||
|
||||
###################################################
|
||||
# #
|
||||
# If database flick.db doesn't exist, create it ! #
|
||||
# #
|
||||
###################################################
|
||||
|
||||
dir=$(dirname "$0")
|
||||
|
||||
if [ ! -f ./flickr.db ]; then
|
||||
./insert.sh
|
||||
fi
|
||||
|
||||
|
||||
perpage=500
|
||||
pages=
|
||||
# getinfo_people
|
||||
username=
|
||||
userid=
|
||||
path_alias=
|
||||
firstdatetaken=
|
||||
photosurl=
|
||||
profileurl=
|
||||
# getinfo_photos
|
||||
photo_id=
|
||||
photo_title=
|
||||
photo_description=
|
||||
photo_posted=
|
||||
photo_taken=
|
||||
photo_view=
|
||||
photo_comments=
|
||||
photo_tags=
|
||||
photo_url=
|
||||
# getAllContexts_photos
|
||||
title_alb=
|
||||
id_alb=
|
||||
title_gro=
|
||||
id_gro=
|
||||
url_gro=
|
||||
# getFavorites_photos
|
||||
favorites=
|
||||
# search_photos
|
||||
search=
|
||||
|
||||
: <<'END_COMMENT2'
|
||||
|
||||
echo -e "\n${BOLD}Most viewed:${COLOR_RESET}"
|
||||
|
||||
req1="SELECT * FROM photos ORDER BY View DESC LIMIT 10;"
|
||||
result1=$(sqlite3 "$ScriptWorkDir/flickr.db" "$req1")
|
||||
|
||||
echo
|
||||
printf "%s%15s %50s %8s %s\n" "${BOLD}" "ID" "Title" "View" "${COLOR_RESET}"
|
||||
|
||||
if [ -n "$result1" ]; then
|
||||
array1=()
|
||||
keywords=()
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array1;
|
||||
do
|
||||
photo_id="${array1[0]}"
|
||||
photo_title="${array1[1]}"
|
||||
photo_view="${array1[5]}"
|
||||
|
||||
printf "%15s %50s %8d \n" "$photo_id" "$photo_title" "$photo_view"
|
||||
|
||||
cmpt=$((cmpt+1))
|
||||
done <<< "$result1"
|
||||
fi
|
||||
|
||||
|
||||
echo -e "\n${BOLD}Most commanted:${COLOR_RESET}"
|
||||
|
||||
req2="SELECT * FROM photos ORDER BY Comments DESC LIMIT 10;"
|
||||
result2=$(sqlite3 "$ScriptWorkDir/flickr.db" "$req2")
|
||||
|
||||
echo
|
||||
printf "%s%15s %50s %8s %s\n" "${BOLD}" "ID" "Title" "Comments" "${COLOR_RESET}"
|
||||
|
||||
if [ -n "$result2" ]; then
|
||||
array2=()
|
||||
keywords=()
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array2;
|
||||
do
|
||||
photo_id="${array2[0]}"
|
||||
photo_title="${array2[1]}"
|
||||
photo_comments="${array2[7]}"
|
||||
|
||||
printf "%15s %50s %8d \n" "$photo_id" "$photo_title" "$photo_comments"
|
||||
|
||||
cmpt=$((cmpt+1))
|
||||
done <<< "$result2"
|
||||
fi
|
||||
|
||||
|
||||
echo -e "\n${BOLD}Most favoris:${COLOR_RESET}"
|
||||
|
||||
req3="SELECT * FROM photos ORDER BY Favorites DESC LIMIT 10;"
|
||||
result3=$(sqlite3 "$ScriptWorkDir/flickr.db" "$req3")
|
||||
|
||||
echo
|
||||
printf "%s%15s %50s %8s %s\n" "${BOLD}" "ID" "Title" "Favorites" "${COLOR_RESET}"
|
||||
|
||||
if [ -n "$result3" ]; then
|
||||
array3=()
|
||||
keywords=()
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array2;
|
||||
do
|
||||
photo_id="${array3[0]}"
|
||||
photo_title="${array3[1]}"
|
||||
photo_comments="${array3[6]}"
|
||||
|
||||
printf "%15s %50s %8d \n" "$photo_id" "$photo_title" "$photo_comments"
|
||||
|
||||
cmpt=$((cmpt+1))
|
||||
done <<< "$result3"
|
||||
fi
|
||||
END_COMMENT2
|
||||
|
||||
|
||||
echo -e "\n${BOLD}Request:${COLOR_RESET}"
|
||||
|
||||
_user_id=14829919@N00
|
||||
|
||||
#request="tags=deer,biche"
|
||||
|
||||
# tags, tag_mode (OR/AND), text (-a term to exclude)
|
||||
# min_upload_date, max_upload_date, min_taken_date, max_taken_date (timestamp or mysql datetime ('YYYY-MM-DD hh:mm:ss'))
|
||||
# sort (date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc, interestingness-asc, and relevance.)
|
||||
# group_id, user_id, media (all/photos/videos), has_geo
|
||||
# extras (description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o)
|
||||
|
||||
|
||||
# text
|
||||
request=""
|
||||
while :
|
||||
do
|
||||
read -e -p "Search text (prefix - to exclude term, or q to quit) in library: " search
|
||||
|
||||
[ "$search" == "q" ] && break
|
||||
if [ "$search" != "q" ] && [ -n "$search" ]; then
|
||||
request="text=${search// /+}"
|
||||
|
||||
[ -n "$request" ] && break 2
|
||||
fi
|
||||
done
|
||||
|
||||
: <<'END_COMMENT3'
|
||||
|
||||
#tag
|
||||
# &text=rencontre+entre+2&format=json
|
||||
request=""
|
||||
while :
|
||||
do
|
||||
read -e -p "Search tags ( or q to quit) in library: " search
|
||||
|
||||
[ "$search" == "q" ] && break
|
||||
if [ "$search" != "q" ] && [ -n "$search" ]; then
|
||||
request="tags=${search// /,}"
|
||||
echo "$request"
|
||||
|
||||
[ -n "$request" ] && break 2
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
#media
|
||||
# &media=video&format=json
|
||||
request=""
|
||||
while :
|
||||
do
|
||||
read -e -p "Search medias (all/photo/video or q to quit) in library: " search
|
||||
|
||||
[ "$search" == "q" ] && break
|
||||
|
||||
if [ "$search" != "q" ] && [[ "$search" =~ all|photo*|video* ]]; then
|
||||
request="media=${search}"
|
||||
|
||||
[ -n "$request" ] && break 2
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
#date
|
||||
request=""
|
||||
utmin=""
|
||||
utmax=""
|
||||
while :
|
||||
do
|
||||
read -e -p "Search dates ('YYYY-MM-DD' or q to quit) in library, from: " search_from
|
||||
[ "$search_from" == "q" ] && break
|
||||
|
||||
read -e -p "Search dates ('YYYY-MM-DD') in library, to: " search_to
|
||||
|
||||
read -e -p "(U)pload date or (T)aken date:" x
|
||||
|
||||
if [ "$x" == "u" ] || [ "$x" == "U" ]; then
|
||||
utmin="min_upload_date"
|
||||
utmax="max_upload_date"
|
||||
elif [ "$x" == "t" ] || [ "$x" == "T" ]; then
|
||||
utmin="min_taken_date"
|
||||
utmax="max_taken_date"
|
||||
fi
|
||||
|
||||
if [ -n "$utmin" ] && [ -n "$utmax" ]; then
|
||||
if [[ "$search_from" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] && [[ "$search_to" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
|
||||
|
||||
search_from="$search_from 00:00:00"
|
||||
search_to="$search_to 23:59:59"
|
||||
|
||||
#request="min_taken_date=${search_from}&max_taken_date=${search_to}"
|
||||
request="$utmin=${search_from}&$utmax=${search_to}"
|
||||
|
||||
request="${request// /+}"
|
||||
request="${request//:/%3A}"
|
||||
|
||||
echo "$request"
|
||||
|
||||
[ -n "$request" ] && break 2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
END_COMMENT3
|
||||
|
||||
if [ -n "$request" ]; then
|
||||
params_search=("$api_key" "$_user_id" "$request")
|
||||
search_photos "${params_search[@]}"
|
||||
fi
|
||||
Reference in New Issue
Block a user