Portál AbcLinuxu, 1. května 2025 07:36
A ty jsi vážně myslel, že o to budou mít zájem?
Pripájam sa k poďakovaniu. Toto je rozhodne lepšia cesta ako nahrávať 100 fotiek cez web. Dík.
noo,.. ani moc ne dival som do Tvojich zdrojakov a urcite by som to nezvladol v rozumnom case. j
skrypt pro českou verzi happyfoto.cz
#!/bin/bash
###################################################
# uploader for happyfoto.sk photo service #
# ver. 1.0 - March 9th, 2009, jose1711 gmail com #
# #
###################################################
# idea from http://groups.google.com/group/cz.comp.linux/browse_thread/thread/4973b67b44e6d5a1
#
# spustenie:
# ./upload-happyfoto [subor1.jpg] [subor2.jpg] [subor3..]
#
# vyzaduje:
# - identify (imagemagick)
# - curl
#
# prihlasovacie udaje (meno/heslo):
# - nacitaju sa zo suboru $HOME/.happyfoto.config (vsetko vratane hesla je
# v plaintexte)
# - priklad:
#user=testuser
#password=testpass
# - ak nie su specifikovane v tomto subore bude zobrazena vyzva na ich zadanie
#
# poznamky:
# - ulozenie hesla v plaintexte nie je velkym problemom, pretoze na zakoncenie
# objednavky je potrebne odoslat potvrdzovaci e-mail
# - subory s rovnakym nazvom, ktore sa uz nachadzaju na serveri, budu prepisane
# bez vyzvy ci varovania
# - na dokoncenie objednavky sa musite prihlasit vo webovom prehliadaci, vybrat
# pocet kopii, velkost atd a potom potvrdit objednavku mailom
# - skript ignoruje adresare (ziadna rekurzia). odporuca sa umiestnit vsetky
# fotografie do jednoho adresara a potom spustit ./upload-happyfoto *
#
# --------------------------------------------------
#
# invocation:
# ./upload-happyfoto [file1.jpg] [file2.jpg] [file3..
#
# required:
# - identify (imagemagick)
# - curl
#
# user credentials:
# - read from $HOME/.happyfoto.config (everything incl. password is plaintext)
# - example:
#user=testuser
#password=testpass
# - if not specified they are prompted on console
#
# notes:
# - storing password in plaintext is not a big deal since successful order requires
# sending confirmation e-mail
# - files with the same name already residing on the server will be overwritten w/o
# notice
# - to finish the order you need to login via webbrowser, select number of copies,
# size, etc. and then confirm via reply e-mail
# - script ignores directories (no recursion). it is advised to put all the photos
# into a common directory and run ./upload-happyfoto *
#
# --------------------------------------------------
# changelog:
# march 9th, 2009 - first public version
####################################################
check_deps(){
which identify &>/dev/null
[ $? -ne 0 ] && echo "ImageMagick not installed, exiting" && exit 1
which curl &>/dev/null
[ $? -ne 0 ] && echo "Curl not installed, exiting" && exit 1
}
show_help(){
echo "A bash script for uploading photos to happyfoto.sk"
echo "Usage:"
echo "./upload-happyfoto [files to upload]"
echo
echo "Example:"
echo "./upload-happyfoto *jpg"
}
read_credentials(){
if [ -f ~/.happyfoto.config ]; then
user=$(sed -n "/^\s*user=/s/^\s*user=\(.*\)/\1/p" ~/.happyfoto.config)
password=$(sed -n "/^\s*password=/s/^\s*password=\(.*\)/\1/p" ~/.happyfoto.config)
fi
if [ -z "${user}" ]; then
until [ ! -z "${password}" ]; do
echo "Zadajte login do happyfoto [Enter login]"
read user
done
else
echo "Login nacitany z .happyfoto.config [Login read from config file]"
fi
if [ -z "${password}" ]; then
until [ ! -z "${password}" ]; do
echo "Zadajte heslo - bude sa zobrazovat [Enter password - will be echoed]"
read password
done
else
echo "Heslo nacitane z .happyfoto.config [Password read from config file]"
fi
}
get_sid(){
sid=$(curl -F 'mnd=4' -F 'txtName='"${user}" -F 'txtPassword='"${password}" 2>/dev/null "http://digi.happyfoto.cz/album?xsl=login_success&action=login&mnd=4" | sed -n "/window.location.href/s/\s*window.location.href = 'album?xsl=standard&action=album&id=\([0-9A-Z]*\)';/\1/p")
}
check_deps
read_credentials
get_sid
# if arguments missing, show help
if [ $# -eq 0 ]; then
show_help
exit 0
fi
echo "SID: $sid"
echo "--------------------------------------------"
echo "Processing $# files:"
counter=0
succ=0
for i in "$@"
do
counter=$((counter+1))
echo -n "uploading file ${i} (${counter}/$#).."
identify "${i}" &>/dev/null
if [ $? -ne 0 ]; then
echo "Skipped (no image format detected)"
elif [ ! -f "${i}" ]; then
echo "Skipped (not a regular file)"
else
curl --no-keepalive -F "Filedata_01=@$i" -F "session=$sid" -F "cut=fit" -F "total_files=1" "http://digi.happyfoto.cz/album?xsl=cart&action=upload&id=$sid" 2>/dev/null | grep order_confirm &>/dev/null
if [ $? -eq 0 ]; then
echo "Success"
succ=$((succ+1))
else
echo "Failed"
fi
fi
done
echo "--------------------------------------------"
echo "Finished (${succ} files uploaded)"
# uploader for happyfoto.sk photo service # echo "A bash script for uploading photos to happyfoto.sk"
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.