Skip to content

Instantly share code, notes, and snippets.

@yamanetoshi
Created August 22, 2018 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamanetoshi/e21c2416228e58020d5aca2a05df5792 to your computer and use it in GitHub Desktop.
Save yamanetoshi/e21c2416228e58020d5aca2a05df5792 to your computer and use it in GitHub Desktop.
gremlin export example
import sys
import csv
from gremlin_python.structure.graph import Graph
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
URL = 'ws://localhost:8182/gremlin'
def main(argv):
import pdb; pdb.set_trace()
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection(URL, 'g'))
if len(argv) < 2:
print('Usage: # python %s LABEL' % argv[0])
quit()
for item in argv[1:]:
with open(item + ".csv", "w", newline="") as outf:
writer = csv.writer(outf, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
lines = g.V().hasLabel(item).toList()
key_list = g.V(lines[0]).properties().key().toList()
key_list.append('label')
writer.writerow(key_list)
for line in lines:
# print(g.V(l).values().toList())
tmp = g.V(line).values().toList()
tmp.append(item)
writer.writerow(tmp)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment