Skip to content

Commit

Permalink
ISSUE-35 Add flag to pycovjson-convert to pipe data into MongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
lewismc committed Jul 11, 2017
1 parent 5c2957b commit 5f83be8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 5 additions & 6 deletions pycovjson/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def main():
help='Name of input file', required=True)
parser.add_argument('-o', '--output', dest='outputfile',
help='Name and location of output file', default='coverage.covjson')
parser.add_argument(
'-t', '--tiled', action='store_true', help='Apply tiling')
parser.add_argument('-t', '--tiled', action='store_true', help='Apply tiling')
parser.add_argument('-s', '--shape', nargs='+',
help='Tile shape, list', type=int)
parser.add_argument('-v', dest='variable',
help='Variable to populate coverage with', required=True)
parser.add_argument('-n', '--interactive', action='store_true', help='Enter interactive mode')
parser.add_argument('-u', '--endpoint_url', dest='endpoint_url', nargs=1, help='MongoDB endpoint for CovJSON persistence')
parser.add_argument('-u', '--endpoint_url', dest='endpoint_url', nargs=1,
help='MongoDB endpoint for CovJSON persistence')
args = parser.parse_args()
inputfile = args.inputfile
outputfile = args.outputfile
Expand All @@ -62,9 +62,8 @@ def main():
if outputfile == None:
outputfile = outputfile.default

if endpoint_url is not None:
Writer(outputfile, inputfile, [variable],
tiled=tiled, tile_shape=tile_shape, endpoint_url=endpoint_url).write()
Writer(outputfile, inputfile, [variable],
tiled=tiled, tile_shape=tile_shape, endpoint_url=endpoint_url).write()

if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion pycovjson/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self, output_name: object, dataset_path: object, vars_to_write: obj
self.ref_list.append(SpatialReferenceSystem2d())
if endpoint_url is not None:
self.endpoint_url = endpoint_url
else:
self.endpoint_url = None

def write(self):
"""
Expand Down Expand Up @@ -206,7 +208,7 @@ def save_covjson_tiled(self, obj, resource):
self.save_json(obj, resource, indent=2)

def save_json(self, obj, resource, **kw):
print("Attempting to write CovJSON manifestation to '%s'" % (resource[0]))
print("Attempting to write CovJSON manifestation to '%s'" % (resource))
start = time.clock()
if resource[0].startswith('mongo'):
mongo_client = MongoDBClient(obj, resource).write()
Expand Down

0 comments on commit 5f83be8

Please sign in to comment.