Permalink
Browse files

Add a bulk export script

  • Loading branch information...
1 parent 497e24f commit 55f4b68981082351c783ccb937d75cff26fc6ed0 @scy committed Feb 25, 2014
Showing with 35 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +34 −0 bulk.sh
View
@@ -1,3 +1,4 @@
+/bulk/
/node_modules/
/resources.ics
/resources.sqlite
View
34 bulk.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# Export all employees to .ics files in the bulk/ directory.
+# Parameters:
+# $1: path to the sqlite database
+# $2: (optional) secret for the file name hash
+
+export dbfile="$1"
+shift
+
+outdir='bulk'
+mapping="$outdir/mapping.txt"
+
+secret="$1"
+
+for nodename in nodejs node; do
+ NODE="$(which "$nodename" 2>/dev/null)"
+ [ -n "$NODE" ] && break
+done
+if [ -z "$NODE" ]; then
+ echo 'Node.js not found in the $PATH' >&2
+ exit 1
+fi
+
+mkdir -p "$outdir"
+
+: >"$mapping"
+
+echo 'SELECT DISTINCT username FROM days;' | sqlite3 "$dbfile" | while read -r employee; do
+ outfile="$(echo "$secret$employee" | sha1sum | cut -b 1-40).ics"
+ echo "$employee -> $outfile ..."
+ echo "$outfile $employee" >>"$mapping"
+ "$NODE" coco-icalres.js "$employee" >"$outdir/$outfile" 2>/dev/null
+done

0 comments on commit 55f4b68

Please sign in to comment.