Created
December 11, 2016 17:50
-
-
Save Babbleshack/77628f7b12fed302ac34800994cb8d98 to your computer and use it in GitHub Desktop.
Simply writes geom jsons to sample files of size sample size
This file contains hidden or 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
| #!/usr/bin/env python | |
| import json | |
| import os | |
| def loadGeoms(geomsJson): | |
| geomsHolder = json.loads(geomsJson) | |
| geoms = geomsHolder['geonames'] | |
| return geoms | |
| def writeNGeomsToFile(geoms, pathToOutputDir = "./output/" , sampleSize = 1): | |
| outputCount = 0 | |
| for geomItter in range(0, len(geoms), sampleSize): | |
| outputCount = writeGeomSetToFile(geoms[geomItter:geomItter + sampleSize] , pathToOutputDir, outputCount) | |
| def writeGeomSetToFile(geomSet, pathToOutputDir, outputCount): | |
| with open(pathToOutputDir + "SAMPLE-" + str(outputCount) + ".json", "w", encoding='latin-1') as geomFile: | |
| geomFile.write(json.dumps(geomSet)) | |
| geomFile.close() | |
| return outputCount + 1 | |
| geomsList = [] | |
| for file in os.listdir('data-files'): | |
| jsonFile = open('data-files/' + file, encoding='latin-1') | |
| geomsList.append(loadGeoms(jsonFile.read())) | |
| jsonFile.close() | |
| print(len(geomsList)) | |
| flat = [val for sublist in geomsList for val in sublist] | |
| writeNGeomsToFile(flat, "./output/", 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment