Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3915856
D1350.id3458.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D1350.id3458.diff
View Options
diff --git a/utils/extract_from_weechat_log.py b/utils/extract_from_weechat_log.py
new file mode 100755
--- /dev/null
+++ b/utils/extract_from_weechat_log.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+
+# Generate the servers log from a weechat IRC log
+# Each log entry is a message on the channel with the following format:
+# [component] entry
+#
+# To get these, you can use the following command:
+#
+# `egrep "\[.*\] .*" log` > candidates
+#
+# Then, you can clean a little bit your candidates entries file.
+#
+# Once done, you can use this script to dump a JSON log:
+#
+# ./extract_from_weechat_log.py candidates
+
+import json
+import os
+import re
+import sys
+
+
+SOURCE = "freenode #nasqueron-ops"
+
+
+def get_component(text):
+ matches = re.match("\[(.*)\] (.*)", text)
+ return matches[1]
+
+
+def get_entry(text):
+ matches = re.match("\[(.*)\] (.*)", text)
+ return matches[2]
+
+
+def get_log_entry_from_line(raw_line):
+ line = raw_line.strip().split('\t')
+ return {
+ "date": line[0].replace(' ', 'T') + "+0000",
+ "emitter": line[1],
+ "source": SOURCE,
+ "component": get_component(line[2]),
+ "entry": get_entry(line[2])
+ }
+
+
+def extract_log(filename):
+ return [get_log_entry_from_line(line) for line in open(filename)]
+
+
+def run():
+ argc = len(sys.argv)
+
+ if argc < 2:
+ print("Usage: {} <log to extract>".format(sys.argv[0]))
+ sys.exit(64)
+
+ filename = sys.argv[1]
+ if not os.path.isfile(filename):
+ print("File not found: " + filename)
+ sys.exit(2)
+
+ log = extract_log(filename)
+ print(json.dumps(log))
+
+
+if __name__ == "__main__":
+ run()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 22:46 (10 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2308293
Default Alt Text
D1350.id3458.diff (1 KB)
Attached To
Mode
D1350: Extract servers log from weechat IRC log
Attached
Detach File
Event Timeline
Log In to Comment