You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This command-line script (report_client.py) provides a simple way to interact with the Reporting service. It allows you to request the generation of three different types of reports (animal, irrigation, or compost) by uploading a corresponding JSON data file.
2
+
3
+
The script handles the entire workflow:
4
+
5
+
It sends the initial request to start the PDF generation process.
6
+
7
+
It waits and periodically checks the server's status.
8
+
9
+
Once the PDF is ready, it downloads the file to the same directory where the script is run.
10
+
11
+
Prerequisites
12
+
13
+
Python 3.6+
14
+
15
+
The requests library. If you don't have it, install it via pip:
16
+
17
+
pip install requests
18
+
19
+
A valid authentication token from the reporting service.
20
+
21
+
A correctly formatted JSON data file for the report you wish to generate.
22
+
23
+
Usage
24
+
25
+
The script is run from your terminal and accepts four command-line arguments.
Generate Report: The script sends a POST request to the appropriate endpoint (e.g., /api/v1/openagri-report/animal-report/) with your token and JSON file. The server accepts the request and returns a unique uuid for the report job.
55
+
56
+
Download PDF: The script then enters a loop, sending GET requests to the retrieval endpoint (e.g., /api/v1/openagri-report/<uuid>/).
57
+
58
+
If the server responds with status 202 Accepted, it means the PDF is still being created, and the script waits a few seconds before trying again.
59
+
60
+
If the server responds with 200 OK, the PDF is ready. The script writes the content to a new file named <uuid>.pdf.
61
+
62
+
The script will retry up to 10 times before timing out.
63
+
64
+
Important Notes
65
+
66
+
The success of the report generation depends entirely on providing a correctly formatted JSON file. If the server's validation fails, the PDF generation will fail.
67
+
68
+
The final PDF file will be saved in the same directory from which you execute the script.
0 commit comments