This is a simple script written to make an API call to one of SingStat's many commonly accessed tables, parse and extract data from the JSON response, and write the output as a .csv file.
This script was originally developed to write the JSON response of the International Visitor Arrivals data as a .csv file.
No. | Subject | Topic | Title | CSV | JSON |
---|---|---|---|---|---|
1 | Tourism | International Visitor Arrivals | International Visitor Arrivals By Inbound Tourism Markets, Monthly | CSV | JSON |
For usage on other commonly accessed tables available on the SingStat website, modification of the script is required by specifying the unique API endpoint, and also depending on which data elements need to be extracted.
Two versions of the script are available.
This version JSON_to_CSV_Local.py
can be executed in the terminal or IDE:
python JSON_to_CSV_Local.py
The output .csv will be saved in the current working directory.
This version JSON_to_CSV_Datorama.py
is modified for use in Datorama to automate the ingestion of data into a Datorama data stream. In this version, the output .csv is automatically uploaded to Datorama and will not be stored on the local machine.
To automate data retrieval in Datorama:
- Specify Frequency (e.g. Daily) and Delivery Hour (e.g. 06)
- Ensure that "Enable Data Retrieval" is selected