Skip to content

Instantly share code, notes, and snippets.

@moretea
Created August 6, 2018 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moretea/b4cf17254eb687b5abe01ca34bee8bd9 to your computer and use it in GitHub Desktop.
Save moretea/b4cf17254eb687b5abe01ca34bee8bd9 to your computer and use it in GitHub Desktop.
Minimal tool to send gremlin query to JanusGraph over the HTTP channel.
#!/usr/bin/env nix-shell
#!nix-shell -p jq -i python3 -p python3Packages.requests
import requests
import json
import atexit
import os
import readline
histfile = os.path.join(".gremlin-history")
try:
readline.read_history_file(histfile)
# default history len is -1 (infinite), which may grow unruly
readline.set_history_length(1000)
except FileNotFoundError:
pass
atexit.register(readline.write_history_file, histfile)
while True:
line = input("$ ")
if line is None:
break
r = requests.post('http://localhost:8182', json= {'gremlin': line})
print("code", r.status_code)
body = r.json()
print(json.dumps(body, indent=2, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment