Skip to content

Instantly share code, notes, and snippets.

@raprasad
Last active August 8, 2018 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raprasad/19f95ebdd570bcfd1448737cff97cc73 to your computer and use it in GitHub Desktop.
Save raprasad/19f95ebdd570bcfd1448737cff97cc73 to your computer and use it in GitHub Desktop.
shareable csv data endpoint

Endpoint

(1) Successful Use:

Send over JSON

  • data - required key with a list of lists

  • filename - optional. if not added, a timestamped file name will be used

  • other keys are ignored

  • Example data:

{
	"data": [["Gender","NA","NA"],["Grade","5.13492063492064","5.13492063492064"],["Age","10.4259259259259","10.4259259259259"],["Race","NA","NA"],["Urban/Rural","NA","NA"],["School","NA","NA"],["Goals","NA","NA"],["Grades","2.6031746031746","2.6031746031746"],["Sports","2.05026455026455","2.05026455026455"],["Looks","2.11640211640212","2.11640211640212"],["Money","3.23015873015873","3.23015873015873"]],
}

Write process

  • The data is first transposed, then written
{
    "success": true,
    "message": "file created!",
    "data": {
        "filename": "/ravens_volume/test_output/185_baseball/temp_storage_root/ta3_data/data_2018-08-08_18-34-51_dtqow.csv",
        "timestamp": "2018-08-08T18:34:51.343"
    }
}

(2) Example of an Error message:

  • Input
{
	"data": [1, 2, 3, 4]
}
  • Output
{
    "success": false,
    "message": "Failed to transpose the data. The data should be a row of rows. Error: zip argument #1 must support iteration"
}

(3) Successful Use with Filename:

  • Input
{
    "filename": "dirname/myfile.csv",
    "data": [["Gender","NA","NA"],["Grade","5.13492063492064","5.13492063492064"],["Age","10.4259259259259","10.4259259259259"],["Race","NA","NA"],["Urban/Rural","NA","NA"],["School","NA","NA"],["Goals","NA","NA"],["Grades","2.6031746031746","2.6031746031746"],["Sports","2.05026455026455","2.05026455026455"],["Looks","2.11640211640212","2.11640211640212"],["Money","3.23015873015873","3.23015873015873"]]
}
  • Output: note position of dirname/myfile.csv
{
    "success": true,
    "message": "file created!",
    "data": {
        "filename": "/ravens_volume/test_output/185_baseball/temp_storage_root/ta3_data/dirname/myfile.csv",
        "timestamp": "2018-08-08T18:43:19.688"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment