Mercurial > org-tools
diff watch-org.pl @ 18:993b8d7d9bec
buggy garbage
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 02 Nov 2011 09:24:54 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/watch-org.pl Wed Nov 02 09:24:54 2011 -0700 1.3 @@ -0,0 +1,50 @@ 1.4 +#!/usr/bin/perl 1.5 + 1.6 +use Linux::Inotify2; 1.7 +use WWW::Mechanize::Firefox; 1.8 +my $mech = WWW::Mechanize::Firefox->new(); 1.9 + 1.10 +my $inotify = new Linux::Inotify2 1.11 + or die "unable to create new inotify object: $!"; 1.12 + 1.13 +$html_files = `find /home/r/proj/{cortex,aurellem,pokemon-types} -name "*.html" -print0`; 1.14 +@html_files = split /\0/, $html_files; 1.15 + 1.16 + 1.17 +#@org_files = glob("./org/*.org"); 1.18 + 1.19 + 1.20 +for $file(@html_files){print "$file\n";} 1.21 + 1.22 +$last_page = ""; 1.23 + 1.24 +foreach(@html_files){ 1.25 +$inotify->watch ($_, IN_MODIFY, sub 1.26 +{ 1.27 + my $e = shift; 1.28 + my $name = $e->fullname; 1.29 + print "**************************\n"; 1.30 + print "$name was modified\n";## if $e->IN_MODIFY; 1.31 + 1.32 + $path = `readlink -f $name`; 1.33 + $path =~ s|/home/r/proj|http://aurellem.localhost|; 1.34 + #$path =~ s|org|html|g; 1.35 + 1.36 + if ($last_page eq $path){ 1.37 + print "reloading current page : $path\n"; 1.38 + $mech->reload(); 1.39 + } 1.40 + else { 1.41 + print "moving to new page : $path\n"; 1.42 + $last_page = $path; 1.43 + $mech->get($path); 1.44 + } 1.45 +}); 1.46 +} 1.47 + 1.48 +# manual event loop 1.49 +while (1){ 1.50 + print "I'm pollin'!"; 1.51 + $inotify->poll; 1.52 + 1.53 +}