Created
April 29, 2017 16:24
-
-
Save osteth/9ec4e233826835f2fdb9c560a60dcabb to your computer and use it in GitHub Desktop.
converts MODIS data over to json fromat from the command line for use in making a REST API from the TXT data files provided
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 csv | |
import json | |
import click | |
@click.group() | |
def cli(*args, **kwargs): | |
"""Command line utility to easily convert .csv data over to .json data. This utility was built for the NASA space apps challenge and is defaulted | |
to be used with cron to pull in data from https://earthdata.nasa.gov/earth-observation-data/near-real-time/firms/active-fire-data convert it to json | |
and load it into a database to overcome the lack of a useable api for this data. | |
Usage: python3 csv-json.py convert -i <input file path> -o <output file path>""" | |
pass | |
@click.command(help='Covert data from csv to json.') | |
@click.option('--input', '-i', default='MODIS_C6_Global_24h.csv', help='--input , -i Sets the file that is to be converted') | |
@click.option('--output', '-o', default='MODIS_C6_Global_24h.json', help='--output, -o, Sets the name of the output.') | |
def convert(input, output): | |
csvfile = open(input, 'r') | |
jsonfile = open(output, 'w') | |
reader = csv.DictReader( csvfile) | |
for row in reader: | |
json.dump(row, jsonfile) | |
jsonfile.write('\n') | |
cli.add_command(convert) | |
if __name__ == '__main__': | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment