From 74784073cdce1b46b47191c7eaafa07b8e49cbb4 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 21 Oct 2015 12:48:16 +0200 Subject: [PATCH] added file-filter python script and README --- contrib/python/.gitignore | 1 + contrib/python/README.md | 11 +++++++++++ contrib/python/file-filter.py | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 contrib/python/.gitignore create mode 100644 contrib/python/README.md create mode 100755 contrib/python/file-filter.py diff --git a/contrib/python/.gitignore b/contrib/python/.gitignore new file mode 100644 index 000000000..0d20b6487 --- /dev/null +++ b/contrib/python/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/contrib/python/README.md b/contrib/python/README.md new file mode 100644 index 000000000..a12819265 --- /dev/null +++ b/contrib/python/README.md @@ -0,0 +1,11 @@ +# Python tools + +These python scripts are intended to manipulate measurements recorded by S2SS's `file` node-type. + +## Exampples + +##### Merge two files and filter the output based on timestamps + +``` +./file-merge.py testfile.dat testfile2.dat | ./file-filter.py 3 5 > output.dat +``` diff --git a/contrib/python/file-filter.py b/contrib/python/file-filter.py new file mode 100755 index 000000000..c7eefd294 --- /dev/null +++ b/contrib/python/file-filter.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import sys + +import s2ss +from s2ss import * + +def main(): + if len(sys.argv) != 3: + print "Usage: %s from to" % (sys.argv[0]) + sys.exit(-1) + + start = s2ss.Timestamp.parse(sys.argv[1]) + end = s2ss.Timestamp.parse(sys.argv[2]) + + for line in sys.stdin: + msg = s2ss.Message.parse(line) + + if start <= msg.ts <= end: + print msg + +if __name__ == "__main__": + main()