# # File: sf/htdocs/books/swift/app/csvtojson.genera.py # # This file is designed to convert a very big (complete?) list of plant # genera (from theplantlist.org) from "comma separated values" format into # json format. This will result in the file becoming much bigger, because # the property names are stored for every object in the json format eg: # [ # { "family": "Myrtaceae", # "genus": "Eucalyptus" } # ... # ] # # Whereas, in the csv format the property names are stored, only once, at # the top of the file. # # This effort is part of the earthtree ios swift app which is # designed to display and map trees in the entire world! one by one! # # I will use the "Codable" swift protocol to convert the json data # to swift objects, and the UITableViews, MapKits etc to display it and # hopefully, to edit it, add to it. # # Usage: # python csvtojson.genera.py > plant.genera.all.json # # Remember to remove the last comma in the generated file !!!! That # extra comma will make the swift Codable encoder not work. # # History: # 3 July 2019 # began to adapt this script from the very similar one "csvtojson.opentrees.py" # import csv with open('plant.genera.all.csv', mode='r') as f: reader = csv.DictReader(f) print "[ " # Output pretty printed geojson data. for row in reader: s = """ {{"family": "{family}", "genus": "{genus}"}},""".format(**row) print s print "] "