Command line zip and submit to an API

Expanding on automating sending data and getting results from the FastAPI I wrote here, that is deployed here.

Tied some command line processing tools together to build out a nice script automation one liner (a long line, but still works) to achieve the goal of zip up a set of files, submit to an API, read the response (JSON) and store that result into a unique runtime record log result

Components needed

  • Zip a file, but make sure it doesn't store the directory paths and wipes out the contents beforehand to make sure that the zip file target doesn't get polluted with unknown and unnecessary information

zip -jr - sample_files >

  • -j Remove the directory information from the file junk_paths
  • r Recursively pick up files
  • - Output to standard IO instead of file
  • target_folder in this case sample_files
  • > Pipe the output to the zip file

curl --location '' --form 'upload_file=@""'

  • --location the API url to submit to
  • --form with the form parameter body in this case upload_file

jq .

  • . Piped input to jq command to format

feed_results_$(date +%Y%m%d%H%M%S).json

  • Name of file plus date command into a format all from Years to seconds to get a unique to the second file name