Add command-line arguments to change default input and output files

This commit is contained in:
Anna Rose 2012-09-10 20:41:29 -04:00
parent e29d54fd34
commit cb7abf01a6

View File

@ -2,6 +2,7 @@
import pygraphviz as pgv
import json
import argparse
# These are the attributes to use for color-coding the graphs
# fixme: make these configurable
@ -27,9 +28,18 @@ relationship_colors = {
}
def parse_args():
parser = argparse.ArgumentParser(description='Generate graphs of polyamorous family networks from data files')
parser.add_argument('--input', '-i', default='network.json', help='Input file in json format')
parser.add_argument('--output', '-o', default='network.png', help='Output image file. Format auto-detected from file extension')
return parser.parse_args()
def main():
settings = parse_args()
try:
data = json.load(open('network.dat', 'r'))
data = json.load(open(settings.input, 'r'))
except Exception as e:
print "Error parsing data file: " + str(e)
return
@ -48,7 +58,7 @@ def main():
graph.add_edge(member1, member2, style=fluid_colors[fluid], color=relationship_colors[rel])
graph.layout()
graph.draw('poly_network.png')
graph.draw(settings.output)
if __name__ == '__main__': main()