Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshaiton <shaiton@fedoraproject.org>2011-05-27 20:17:06 (GMT)
committer shaiton <shaiton@fedoraproject.org>2011-05-27 20:17:06 (GMT)
commit8cd7af1fbf310d9cc203b6c0a03d6f2d5715548e (patch)
treeb5cb1c8c831db7a8888e708525bbb187e6b01d33
original script added
-rwxr-xr-xjparser119
1 files changed, 119 insertions, 0 deletions
diff --git a/jparser b/jparser
new file mode 100755
index 0000000..b9edcde
--- /dev/null
+++ b/jparser
@@ -0,0 +1,119 @@
+#!/bin/bash
+
+# Features:
+#
+# output format will be as defined by the variable $template
+# for exemple
+# org.laptop.WebActivity:1305831706:b7b8928d-b203-4aea-8924-f5a070637282:OLPC:0:
+# in a file named like user_YYYY-MM-DD.txt
+
+
+metadata=.metadata
+path=$PWD
+callme=child
+separator=:
+template=#activity${separator}timestamp${separator}uid${separator}title${separator}title_set_by_user${separator}buddies
+user=$USER
+
+helpme()
+{
+ echo "Usage: $0 [user_name] [path to $metadata files]."
+ echo " add -h as first arg to print this help"
+ echo " - if no path specified, the current dir would be used"
+ echo ' - if no user name is specified, the current $USER would be used' #should check an XO id
+ echo 'Ex of call: ./jparser $USER .'
+ exit 0
+}
+
+#
+# Fuction used to get the value from the key pairs
+#
+
+get_sed()
+{
+ echo $1 | sed "s/.*://"
+}
+
+
+#
+# function used to parse all metadata files from $path
+#
+
+parse()
+{
+ out=$2
+ # create template file
+ if [ ! -f $out ]; then
+ echo $template > $out
+ fi
+
+ tmp=$(sed -e 's/": ["]/:/g;s/["], "/#/g;s/^{"//g;s/: ""}//g;s/": /:/g;s/, "/#/g;s/"}//g' $1)
+
+ IFS='#' read -ra ADDR <<< "$tmp"
+ for i in "${ADDR[@]}"; do
+ if [[ $i == *epub* ]]; then
+ activity=epub # litle trick cause ebooks as epub have no activity saved
+ fi
+ case $i in # Because not all metadafiles use the same template, we have to look for each part one by one.
+ *title_set*) title_set=`get_sed $i`;;
+ *title:*) title=`get_sed $i`;;
+ *uid*) uid=`get_sed $i`;;
+ *timestamp*) timestamp=`get_sed $i`;;
+ *activity:*) activity=`get_sed $i`;;
+ *buddies*) buddies=`get_sed $i`;;
+ esac
+ done
+
+ line=${activity}${separator}${timestamp}${separator}${uid}${separator}${title}${separator}${title_set}${separator}${buddies}
+ echo $line >> $out
+ exit 0
+}
+
+#
+# Start argument processing
+#
+
+if [[ "$#" -gt 3 || "$1" = "-h" ]]; then
+ helpme
+fi
+
+#
+# Am I a child process used for parsing?
+#
+
+if [[ "$1" = "$callme" ]]; then
+ if [ ! "$#" = 3 ]; then
+ echo "Error there should have been 3 args: callme path filename"
+ echo " But you give me: $*"
+ exit 1
+ else
+ parse $2 $3
+ fi
+fi
+
+#
+# Path provided as arg?
+#
+
+if [ $# -lt 3 ]; then
+ path=$2
+fi
+
+#
+# User provided as arg?
+#
+
+if [[ -n "$1" ]]; then
+ user=$1 # it could also be found somewhere, depending where this script is used (XO or XS?)
+fi
+
+#
+# Let's start parsing
+#
+
+out=${user}_`date +%F`.txt
+# Now we call ourself to be able to inter in the function. Also used to run in concurrency
+find $path -name "*$metadata" -exec $0 $callme '{}' $out \;&
+wait # wait the end of parsing
+echo "Metadata could be find in $out"
+exit 0