Created
August 22, 2018 12:19
-
-
Save yamanetoshi/e21c2416228e58020d5aca2a05df5792 to your computer and use it in GitHub Desktop.
gremlin export example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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