Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Copyright (c) 2011 Federico Ch. Tomasczik (LW3ESH)
- # E-Mail: <ftomasczik at gmail dot com>
- #
- # savemeqsl (Save Me eQSL) is free software: you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as published
- # by the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # savemeqsl is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with savemeqsl. If not, see <http://www.gnu.org/licenses/>.
- #
- ###########################################################################
- # Thanks to:
- #
- # Cezar, YO3FHM
- # Jan, ES6JAN
- # Albert, EA3CFV
- ###########################################################################
- VERSION=0.2.0
- TMP="/var/tmp"
- URL="http://www.eqsl.cc/qslcard/"
- # Print the version number:
- function printVersion
- {
- echo ""
- echo $"Save Me eQSL: savemeqsl version $VERSION."
- echo $"Simple bash script for download yours Electronic QSL cards from eQSL.cc site."
- echo ""
- echo $"Latest version is at :"
- echo ' http://code.google.com/p/savemeqsl/'
- echo ""
- echo " 73 de LW3ESH, Federico Ch. Tomasczik"
- echo ""
- }
- # Funtion to print the help and exit:
- function printHelpAndExit
- {
- exitCode=$1
- echo $" Usage $0: [-hvoVq] -u callsign -p passwrd -d directory."
- echo $" -h, --help print this help."
- echo $" -v, --version show version."
- echo $" -o, overwrite ALL eQSL files."
- echo $" -q, --quiet don't show any information."
- echo $" -u your callsign or user in eQSL.cc."
- echo $" -p your password in eQSL.cc."
- echo $" -d directory where save yours eQSL."
- exit $exitCode
- }
- # Function to show fatal errors and exit:
- function showErrorAndExit
- {
- exitCode=$2
- printf "$1"
- exit $exitCode
- }
- # Function to read the users options:
- function parseOptions
- {
- while getopts "hvou:p:d:-help-verbose-version-quiet" OPTION; do
- case "$OPTION" in
- h|--help) printHelpAndExit 0;;
- v|--version) printVersion;exit 0;;
- q|--quiet) QUIET="Y";;
- o) OVERWRITE="Y";;
- u) USER=$OPTARG;;
- p) PASS=$OPTARG;;
- d) DESTINATION=$OPTARG
- # Check if $DESTINATION exist.
- if [ ! -d $DESTINATION ];then
- showErrorAndExit $"The directory $DESTINATION does not exist!\nCheck this and try again.\n" 20
- else
- # Check if $DESTINATION if writeable for the user.
- if [ ! -w $DESTINATION ]
- then
- showErrorAndExit $"You can not write into $DESTINATION!\nCheck this and try again.\n" 20
- fi
- fi;;
- [?]) showErrorAndExit $"Option not recognised.\nTry '$0 -h´ for more information.\n" 21;;
- esac
- done
- }
- # Function to connect to eQSL site and get cookies:
- function eQSLConnect
- {
- if [ ! "$QUIET" ];then
- echo $" Connecting to eQSL site..."
- fi
- wget -T 25 -q --cookies=on --keep-session-cookies --save-cookies="$TMP/cookie.txt" -O "$TMP/tmp.txt" $URL"LoginFinish.cfm?Callsign="$USER\&EnteredPassword=$PASS\&Login=Go
- }
- # Function to login to eQSL site:
- function eQSLLogin {
- if [ ! "$QUIET" ];then
- echo $" Login to eQSL site..."
- fi
- wget -T 25 -q --referer $URL"LoginFinish.cfm?Callsign="$USER\&EnteredPassword=$PASS\&Login=Go --cookies=on --load-cookies="$TMP/cookie.txt" --keep-session-cookies --save-cookies="$TMP/cookie.txt" -O "$TMP/tmp.txt" $URL"DownloadInBox.cfm"
- # If file tmp.txt contain 'You are not yet logged in' then...
- t=`grep "You are not yet logged in" $TMP/tmp.txt`
- if [ -n "$t" ];then
- showErrorAndExit $" User or password are incorrect.\nPlease, try again.\n" 21
- else
- if [ ! "$QUIET" ];then
- echo $" Login OK..."
- fi
- fi
- }
- # Function to get your loogbook:
- function getLogBook
- {
- t=`grep ".TXT file" $TMP/tmp.txt | cut -d '"' -f2`
- if [ -z $t ]; then
- showErrorAndExit $"The file $TMP/tmp.txt don't look like a loogbook.\n" 22
- fi
- if [ ! "$QUIET" ];then
- echo $" Downloading you logbook file..."
- fi
- wget -T 25 -q --referer $URL"LoginFinish.cfm?Callsign="$USER\&EnteredPassword=$PASS\&Login=Go --cookies=on --load-cookies="$TMP/cookie.txt" --keep-session-cookies -O "$TMP/log.txt" $URL$t
- if [ ! "$QUIET" ];then
- echo $" Reading you logbook file..."
- fi
- }
- # Function to get the eQSL images:
- function getQSL
- {
- grep "<CALL:" $TMP/log.txt | while read LINE
- do
- export n=0
- CALLSIGNAL=$(echo $LINE | cut -d '<' -f2 | cut -d '>' -f2)
- DATE=$(echo $LINE | cut -d '<' -f3 | cut -d '>' -f2)
- TIME=$(echo $LINE | cut -d '<' -f4 | cut -d '>' -f2)
- BAND=$(echo $LINE | cut -d '<' -f5 | cut -d '>' -f2)
- MODE=$(echo $LINE | cut -d '<' -f6 | cut -d '>' -f2)
- FILE_NAME=$CALLSIGNAL"_"$DATE"_"$TIME"_"$BAND"_"$MODE
- FILE_NAME=$(echo $FILE_NAME|sed 's/\//-/g')
- YEAR=$(expr substr $DATE 1 4)
- MONTH=$(expr substr $DATE 5 2)
- DAY=$(expr substr $DATE 7 2)
- HOUR=$(expr substr $TIME 1 2)
- MINUTE=$(expr substr $TIME 3 2)
- TIME="$(expr substr $TIME 1 2)":"$(expr substr $TIME 3 2)"
- DATE="$(expr substr $DATE 1 4)"-"$(expr substr $DATE 5 2)"-"$(expr substr $DATE 7 2)"
- wget -T 25 -q --referer $URL"LoginFinish.cfm?Callsign="$USER\&EnteredPassword=$PASS\&Login=Go --cookies=on --load-cookies="$TMP/cookie.txt" --keep-session-cookies -O "$TMP/tmp.txt" $URL"DisplayeQSL.cfm?Callsign="$CALLSIGNAL"&VisitorCallsign="$USER"&QSODate="$DATE"%20"$TIME"&Band="$BAND"&Mode="$MODE
- # For default, the images are in .PNG
- URL_IMG=`grep ".PNG" $TMP/tmp.txt | cut -d '"' -f2 | cut -d '/' -f4`
- if [ -z "$URL_IMG" ]; then
- # If $URL_IMG is null, then check por .JPG:
- URL_IMG=`grep ".JPG" $TMP/tmp.txt | cut -d '"' -f2 | cut -d '/' -f4`
- FILE_NAME=$FILE_NAME".jpg"
- else
- FILE_NAME=$FILE_NAME".png"
- fi
- if [ -f $DESTINATION"/"$FILE_NAME ] && [ ! $OVERWRITE ];then
- if [ ! "$QUIET" ];then
- echo $" The $FILE_NAME exists. No overwrite it."
- fi
- else
- if [ ! "$QUIET" ];then
- echo $" Downloading eQSL for you QSO with $CALLSIGNAL..."
- fi
- wget -T 25 -q -O $DESTINATION"/"$FILE_NAME "http://www.eqsl.cc/CFFileServlet/_cf_image/$URL_IMG"
- # Check the file size. If this is 0 byte, then it is removed.
- FILE_SIZE=`stat -c %s $DESTINATION"/"$FILE_NAME`
- if [ $FILE_SIZE -eq 0 ]; then
- rm $DESTINATION"/"$FILE_NAME
- echo " Some error ocurred with the eQSL http://www.eqsl.cc/CFFileServlet/_cf_image/$URL_IMG"
- fi
- fi
- done
- }
- # Function to remove all temporary files
- function clearFiles
- {
- if [ -f "$TMP/cookie.txt" ];then
- rm "$TMP/cookie.txt"
- fi
- if [ -f "$TMP/tmp.txt" ];then
- rm "$TMP/tmp.txt"
- fi
- if [ -f "$TMP/log.txt" ];then
- rm "$TMP/log.txt"
- fi
- }
- ##########################################################################
- # The script start here!
- #
- # Read user options:
- parseOptions "$@"
- # Connect to eQSL site and save cookies:
- eQSLConnect
- # Login to eQSL site:
- eQSLLogin
- # Get your loogbook:
- getLogBook
- # Start eQSL download:
- getQSL
- # Remove all temporary files
- clearFiles
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement