aboutsummaryrefslogtreecommitdiff
path: root/i3/bin/cloogle_stats.py
diff options
context:
space:
mode:
authorCamil Staps2017-02-20 10:06:38 +0100
committerCamil Staps2017-02-20 10:06:38 +0100
commit73ae3a47a410eb2db9c3c776c0252e1feaeb2d7e (patch)
tree4835551f5d769ede433ed390d3cfc2406975480c /i3/bin/cloogle_stats.py
parentCloogle stats in status bar (diff)
Reorganise binaries
Diffstat (limited to 'i3/bin/cloogle_stats.py')
-rwxr-xr-xi3/bin/cloogle_stats.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/i3/bin/cloogle_stats.py b/i3/bin/cloogle_stats.py
new file mode 100755
index 0000000..0c48b70
--- /dev/null
+++ b/i3/bin/cloogle_stats.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+import json
+import ssl
+import websocket
+
+def format_query(query):
+ if 'className' in query:
+ return 'class ' + query['className']
+ elif 'typeName' in query:
+ return 'type ' + query['typeName']
+ elif 'unify' in query:
+ if 'name' in query and query['name'] != '':
+ return query['name'] + ' :: ' + query['unify']
+ else:
+ return ':: ' + query['unify']
+ else:
+ return query['name']
+
+def on_message(ws, msg):
+ try:
+ print(format_query(json.loads(msg)))
+ except:
+ pass
+
+def on_error(ws, err):
+ print(err)
+
+def on_close(ws):
+ print('Closed.')
+
+if __name__ == '__main__':
+ ws = websocket.WebSocketApp('wss://cloogle.org:31216',
+ subprotocols=['cloogle-stats'],
+ on_message=on_message, on_error=on_error, on_close=on_close)
+ ws.run_forever(sslopt={'cert_reqs': ssl.CERT_NONE})