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 > sample_input.zip
-j
Remove the directory information from the filejunk_paths
r
Recursively pick up files-
Output to standard IO instead of filetarget_folder
in this casesample_files
>
Pipe the output to the zip file
curl --location '
https://google-vr-calculator.district9.info/feed?external_id=rental1&start_date=2024-02-01&end_date=2024-02-08&booked_date=2023-10-21
' --form 'upload_file=@"sample_input.zip"'
--location
the API url to submit to--form
with the form parameter body in this caseupload_file
.
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