Friday, January 4, 2019

find and regular expression tools to make json from file listings

Somehow I keep forgetting that I made a tool called regexcellent to let me do quick and dirty regex manipulations from the browser - stuff I used to do in text editor macros or small Perl scripts. (It and a bunch of other small tools, mostly for text manipulation, some of dubious quality, live at https://kirk.is/tools/...)

I'm starting to add photos to my timeline project - they really add to the emotional power of it for me. I wanted to make a new timeline of big trips I've taken - I already have a lot of photo galleries online so it was a matter of harvesting from there, using the galleries both for the images and just as a reminder of what trips I've taken, and when.

I stumbled onto having "one folder per trip", each name "yyyy mm tripname" and each containing a single jpeg. And my JSON format for each entry is something like
 {name:'boston', from:{y:1991 , m:03 }, to:{y:1991, m:03}, 
  img:'trips/1991 03 boston/043_560.1991 jazz band in boston.jpg'},

so from the shell, I ran
find . | grep -i jp | sort
which was good enough to get me the list of jpegs in a format like 
./1991 03 boston/043_560.1991 jazz band in boston.jpg
and then at regexcellent the matcher was 
^\.\/(\d\d\d\d) (\d\d) (.*)\/(.*)$
and the output pattern was
{name:'$3', from:{y:$1 , m:$2 }, to:{y:$1, m:$2}, img:'trips/$1 $2 $3/$4'},

A little comma cleanup and I was done!

To quote Douglas Adams, "[I] am rarely happier than when spending an entire day programming my computer to perform automatically a task that would otherwise take me a good ten seconds to do by hand."

No comments:

Post a Comment