Friday, February 10, 2012

#shellscript to download #flickr photo sets

This is #shell #script #shellscript that will retrive public sets of #flickr images.  It creates a directory with the name of the flickr user and it moves all the files into that directory.

If you find it useful, let me know what you think.



#!/bin/sh

# A friend asked me to write a script to download a flickr set of images
# that are Publicly available.
#
# So, here it is, my first attempt
# If you have any questions shoot me an email yaxzone@yaxmail.com
# If you are going to be running this script on Linux, make sure to
# uncomment out line 28 and comment out line 29

## Set to download 
# ***** Replace this url with the SET you would like to download *****
Set="http://www.flickr.com/photos/crustydolphin/sets/72157618053451592/detail/"

# Size of files 
SizeImage="_z.jpg" # This is the medium size
SizeImage1="_b.jpg" # Large size if available

# Creates directory with the name of the user
Dir=`echo $Set | cut -d'/' -f5` 


function ComponentsDownload { # This function gets all the pages number
mkdir -p $Dir
PagesCalc=`lynx -dump $Set | grep 'page' | awk '{print $2}' | sort -d | uniq | cut -d'=' -f2 | sort -n | tail -1`
PagesCalcPlus1=$(expr $PagesCalc + 1)

#for PageNumb in `seq 1 $PagesCalcPlus1` # For Linux usage
for PageNumb in `jot - 1 $PagesCalcPlus1` # For Mac OS X usage

do

echo $Set"?page="$PageNumb >> Pages.txt

done

# This pices gets all the links to the pictures on the pages
for ImagesUrl in `cat Pages.txt | awk '{print $1}' | sort -d | uniq` 

do 
lynx -dump $ImagesUrl | grep 'in/set-' | awk '{print $2}' | sort -d | uniq >> ImagesUrl.txt

done
echo "First part of job done."
echo "Hold on tight ..."
}

function DownloadImages { # This funcion starts the actual download of the images
for ImageUrl in `cat ImagesUrl.txt | sort -d | uniq`

do

curl $ImageUrl | grep "url: 'http://" | grep "$SizeImage\|$SizeImage1" | cut -d"'" -f2  > Image2Download 2>&1

WhichFile=`grep '_b.jpg' Image2Download`

if [ ! -z "$WhichFile" ]; # This piece determines which file to download
then 

File2Download=`cat Image2Download | tail -1`
echo $File2Download

else 

File2Download=`cat Image2Download | head -1`
echo $File2Download

fi

wget $File2Download > /dev/null 2>&1
File2Move=`echo $File2Download | cut -d'/' -f5`
mv $File2Move $Dir"/"
rm Image2Download
sleep 1 # Waits 1 second before it downloads the second image

done
}

function CleanUp { # Removes the pages where the urls get stored
rm ImagesUrl.txt
rm Pages.txt

# this piece renames the files for the ones that have extra characters
cd $Dir
ls -1 | grep '.jpg?' | while read File; do mv $File `echo $File | cut -d'?' -f1`; done
cd ..
}

# This executes the above functions
ComponentsDownload
DownloadImages
CleanUp

echo "Job done."

Monday, January 23, 2012

A little joke for your day ...






I have written this shell script to get some jokes in my daily routine. If you are like me, you probably open several terminal windows during the day.

If that is the case, how about a little joke to keep it fun.

This script does a few things:

  1. Gets jokes from the good folks at http://www.randomjoke.com/ (Please support them if you can.)
  2. It formats the returned joke so it can be printed on the terminal screen
  3. Since some of the jokes are pretty funny, I decided to add functionally to update the status on Adium/Skype with the returned "oneliners" joke

I've tested this with Snow Leopard and Leopard on the Mac, also Ubuntu 11.10 and Ubuntu 11.04 (The Ubuntu part is only for printing on the terminal not Adium/Skype).

In Linux, with the sed command, line 69 and 73 on the script, remove the set of empty "" double quotes.

If you are not going to use the Adium/Skype functionally, feel free to use the other "Joke Categories" which are pretty funny.

Shout me an email if you have any questions yaxzone@yaxmail.com


Sunday, January 22, 2012

My beautiful wife ...

My beautiful wife ... by YAXZONE
My beautiful wife ..., a photo by YAXZONE on Flickr.

with built-in flash here...

Tuesday, December 20, 2011

Apple Time Machine and error 45 when using it on a network drive

I just started using Time Machine (Yeah, I know, i'm late to the party) on some Macs I have and to my surprise things did not work from the get go, very un-Apple-like. This occurred on v10.6.8 and v10.5.x.

Anyway, to make it short, I've written a script that fixes this.

Some of the information I pieced together came from this guy's article (http://www.levelofindirection.com/journal/2009/10/10/using-a-networked-drive-for-time-machine-backups-on-a-mac.html).

So, if you get the following error, have at it:

Time Machine could not complete the backup.
The backup disk image "/Volumes/*/*.sparsebundle" could not be created (error 45).

----- Script Starts -----
#/bin/sh
# Luis Yax - info@yaxmail.com
# This script fixes the below error when setting up TimeMachine on Mac OS X v10.6.8, error 45

clear;
echo -e "\nCurrent Volumes mounted: "
ls -1 /Volumes/ | nl; echo " "
echo "Enter your TimeMachine Volume name (if not sure, just press enter): "
read VolumeNameEntered
ComputerName=`hostname`
ComputerMACAddress=`ifconfig | grep -A 1 'en0' | grep "ether" | awk '{print $2}' | sed 's/://g'`
if [ -z "$VolumeNameEntered" ];
then
echo "VolumeName is empty"
else
MyTimeMachine=$VolumeNameEntered
fi
echo "sparsebundle being created, hold on tight ..."
hdiutil create -size 320g -type SPARSEBUNDLE -nospotlight -volname "Backup of $ComputerName" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/$ComputerName"_"$ComputerMACAddress.sparsebundle > /tmp/MyTimeMachineScriptSetup.log 2>&1
IfSuccess=`grep "created: " /tmp/MyTimeMachineScriptSetup.log | awk '{print $5}'`
IfSuccessAnswer=`echo ${IfSuccess//[[:space:]]}`
clear
if [[ "IfSuccessAnswer" -eq "0" ]] && [[ ! -z "$VolumeNameEntered" ]];
then
echo "Now moving sparsebundle to TimeMachine Volume ..."
echo "Job completed successfully."
else
echo "The following sparsebundle will have to be moved manually to your TimeMachine volume:"
echo "~/Desktop/"$ComputerName"_"$ComputerMACAddress".sparsebundle"
fi
rm /tmp/MyTimeMachineScriptSetup.log

----- Script Ends -----

Saturday, December 17, 2011

_MG_3223

_MG_3223 by YAXZONE
_MG_3223, a photo by YAXZONE on Flickr.

Our little "Lady Bug" :)

Saturday, September 25, 2010

@ Alexis soccer practice


DSC02654
Originally uploaded by YAXZONE
I love my wife...

Saturday, July 31, 2010

CLI first post

This probably will make me starg bloggin more often... Great work googlers