Hey!
This is used for me on my Linux workstation to get a notification if there is a new spotify release whenever I open a new terminal.. It would be applicable for other (probably also simple) pages that aren’t updated frequently.
Reason: http://repository.spotify.com/pool/non-free/s/spotify/
I wanted to see if there was a new spotify release for Linux/QT.
Method: The URL is above – but what if I do not want to go there every day and get disappointed?
Way nicer to have a script do it for me.
This script saves the index.html from the URL above of each day.
Then each day when it downloads the .html it checks if it’s different from yesterday.
This has its limitations, if there is an update in the weekend I will never know.
The script should check the last x amount of days and if any of them are different from today it should tell me. The script checks if any of the files are different from today, if so, it will write something into another file. The script then checks if this file is non-empty, if it has data in it, it will write to this other file that. Tada. :p
If it is, then it will write to a file that is referenced in $HOME/.bashrc.
The layout of the blog doesn’t like really long lines in <pre>, but you can select below and only get the post (and not the stuff on the right side).
spot_check.sh:
#!/bin/sh dat1=$(date +%Y.%m.%d) daty=$(perl -MPOSIX=strftime -le 'print strftime "%Y.%m.%d",localtime (time - 86400)') dat2=$(perl -MPOSIX=strftime -le 'print strftime "%Y.%m.%d",localtime (time - 172800)') dat3=$(perl -MPOSIX=strftime -le 'print strftime "%Y.%m.%d",localtime (time - 259200)') dat4=$(perl -MPOSIX=strftime -le 'print strftime "%Y.%m.%d",localtime (time - 345600)') dat5=$(perl -MPOSIX=strftime -le 'print strftime "%Y.%m.%d",localtime (time - 432000)') path="$HOME/Downloads/Spotify/saved" out="$HOME/Downloads/Spotify/diff.log" bout="$HOME/.spotcheck" wget -q http://repository.spotify.com/pool/non-free/s/spotify/ -O $path/$dat1.html diff -q $path/$dat1.html $path/$daty.html > $out diff -q $path/$dat1.html $path/$dat2.html >> $out diff -q $path/$dat1.html $path/$dat3.html >> $out diff -q $path/$dat1.html $path/$dat4.html >> $out diff -q $path/$dat1.html $path/$dat5.html >> $out if [[ -s $out ]] ; then echo $out "is not empty"; echo "#!/bin/sh" > $bout; echo "echo new spotify release" >> $bout; chmod +x $bout; else echo $out "is empty"; echo "No new spotify release."; rm $bout; fi;Crontab (daily at 0915):
15 09 * * * /bin/bash /home/username/Downloads/Spotify/spot_check.sh 2>&1.bashrc:
if [ -f ~/.spotcheck ]; then cd $HOME ./.spotcheck fi On Mon, 14 Nov 2011 23:06:15 -0600 Chris Stinemetz <chrisstinemetz@gmail.com> wrote: > Thank you Shlomi. > > For some reason my final value for the keys is being repeated 24 times so I > am guessing I have an issue with how I am iterating over the hashes. > > I can't seem to find the correct way to fix it so the value displays once. > In such cases, you should use a debugger: http://perl-begin.org/topics/debugging/ > Any help is greatly appreciated. > > An example of the output is: Snipped. > #!/usr/bin/perl > use warnings; > use strict; > use POSIX; > use Data::Dumper; > use diagnostics; > my $filepath = > sprintf("/omp/omp-data/logs/OMPROP1/%s.APX",strftime("%y%m%d",localtime)); > my $runTime = > sprintf("/home/cstine/heh/hehOut/%s.txt",strftime("%Y-%m-%d",localtime)); > my $fileDate = strftime("%y%m%d%H%",localtime); > open my $FIN, '<', $filepath or die "ERROR opening $filepath: $!"; > open my $out, '>', $runTime or die "ERROR opening $runTime: $!"; > > my %CELL; > my $timestamp; > my $hour; > while (my $line = <$FIN>) { > if ($line =~ m|\d{1,2}/\d{1,2}/\d{2} ((\d{1,2}):\d{1,2}:\d{1,2})|) { > $timestamp = $1; > $hour = $2; > } > if ($line =~ /CELL\s*(\d+)\s*(.*),\s*HEH/) { > if ((0 <= $hour)&&($hour <=23)) { > $CELL{$hour}{$1}{$2}++; > } > } > } > # header > print "HOUR\tCELL\tHEH_TYPE\t\tHEH_COUNT\n"; > # body > foreach my $hour (sort keys %CELL) { > foreach my $cellNo (sort keys %{$CELL{$hour}}) { > foreach my $hehType (sort keys %{$CELL{$hour}{$cellNo}}) { Please implement my suggestion of doing: foreach my $hour (sort keys %CELL) { my $hour_rec = $CELL{$hour}; # Do something with $hour and $hour_rec. > print "$hour\t$cellNo\t$hehType"; Do you intend to print it only once? > foreach my $hehCount (sort keys %CELL) { > print ",$CELL{$hour}{$cellNo}{$hehType}"; The problem here is that you're iterating with $hehCount but accessing the inner-most hash-reference using $hehType. So it will always print the same value. I also don't understand why there's another foreach loop to the keys of %CELL here. Regards, Shlomi Fish > } > print "\n"; > } > } > } > thank you , > > Chris -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.shlomifish.org/ Chuck Norris can make the statement “This statement is false.” a true one. Please reply to list if it's a mailing list post - http://shlom.in/reply . Thread Previous | Thread Next- complex data structure by Chris Stinemetz
- Re: complex data structure by Chris Stinemetz
- Re: complex data structure by Shlomi Fish
- Re: complex data structure by Chris Stinemetz
- Re: complex data structure by Shlomi Fish
- Re: complex data structure by Jim Gibson
- Re: complex data structure by Shlomi Fish
Relevant pages:
- Perl Databases
- Perl Assignment Operators
- Apache Download Mysql Perl Php Server Window
- Perl Blowfish
- Greedy Match Perl




