1st commit
This commit is contained in:
121
flickr.sh
Executable file
121
flickr.sh
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/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"
|
||||
|
||||
perpage=500
|
||||
pages=
|
||||
username=
|
||||
userid=
|
||||
path_alias=
|
||||
firstdatetaken=
|
||||
photosurl=
|
||||
profileurl=
|
||||
|
||||
|
||||
###################################################
|
||||
# #
|
||||
# Get info about the given user. #
|
||||
# #
|
||||
###################################################
|
||||
|
||||
params_info=("$api_key" "$user_id")
|
||||
getinfo_people "${params_info[@]}"
|
||||
|
||||
echo -e "\n${COLOR_GREEN}Get info about user ($user_id).${COLOR_RESET}"
|
||||
|
||||
printf "%15s %50s\n" "Name:" "$username"
|
||||
printf "%15s %50s\n" "Alias:" "$path_alias"
|
||||
printf "%15s %50s\n" "UserID:" "$userid"
|
||||
printf "%15s %50s\n" "Joined:" "$firstdatetaken"
|
||||
printf "%15s %50s\n" "Gallery:" "$photosurl"
|
||||
printf "%15s %50s\n" "Profile:" "$profileurl"
|
||||
|
||||
|
||||
|
||||
###################################################
|
||||
# #
|
||||
# Get a list of public photos for the given user. #
|
||||
# #
|
||||
###################################################
|
||||
|
||||
#photos=$(curl "https://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=$api_key&user_id=$user_id&per_page=500&page=2&format=json&nojsoncallback=1")
|
||||
|
||||
echo -e "\n${COLOR_GREEN}Get a list of public photos for the given user ($user_id).${COLOR_RESET}"
|
||||
|
||||
echo -e "One request per page..."
|
||||
|
||||
#for page in {1..2}
|
||||
for (( page=1; page <=$pages; page++ ))
|
||||
do
|
||||
#echo "Page $page"
|
||||
curl -s "https://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=$api_key&user_id=$user_id&per_page=500&page=$page&format=json&nojsoncallback=1" | jq '.photos | .photo' > "page${page}.json"
|
||||
done
|
||||
|
||||
echo -e "Concatenate all pages in liste.json"
|
||||
|
||||
allpages=$(ls page*.json | tr '\n' ' ')
|
||||
|
||||
#jq -s 'add' page1.json page2.json > liste.json
|
||||
jq -s 'add' ${allpages} > liste.json
|
||||
|
||||
echo -e "Display all images list..."
|
||||
|
||||
photos=$(cat liste.json)
|
||||
ID=()
|
||||
counter=1
|
||||
|
||||
while read -r id && read -r title; do
|
||||
echo -e "${BOLD}Photo ID: ${id}\t Title: ${title}${COLOR_RESET}"
|
||||
|
||||
params_info=("$api_key" "$id")
|
||||
getinfo_photos "${params_info[@]}"
|
||||
|
||||
ID+=(${id})
|
||||
((++counter))
|
||||
done < <(jq -r -c '.[] | .id, .title' <<< "$photos")
|
||||
|
||||
echo -e "${COLOR_GREEN}Found $counter public photos for user ($user_id) on Flickr.${COLOR_RESET}"
|
||||
|
||||
#echo ${ID[@]}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user