diff master/wecu/sac_mapper.py @ 57:ac1a20e627a9

from lukasz git repo 2020-05-26 (see ~/src/wecu), then editted, sac not quite working yet
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 27 May 2020 20:54:34 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/wecu/sac_mapper.py	Wed May 27 20:54:34 2020 +0000
@@ -0,0 +1,25 @@
+#!/usr/bin/python3
+import os
+import sys
+import re
+
+is_regex = sys.argv[1] == 'true'
+search_terms = sys.argv[2:]
+search_terms_counters = dict()
+
+# Initialise
+for term in search_terms:
+    search_terms_counters[term] = 0
+
+if not is_regex:
+    for line in sys.stdin:
+        for term in search_terms_counters:
+            search_terms_counters[term] += line.count(term)
+else:
+    for line in sys.stdin:
+        for term_regex in search_terms_counters:
+            search_terms_counters[term_regex] += len(re.findall(term_regex, line))
+
+
+for term in search_terms_counters:
+    print("{}\t{}".format(term, search_terms_counters[term]))