Skip to main content

Commands to download datasets from the Open Data portal of the Kingdom of Saudi Arabia (KSA).

Project description

Open Data - Kingdom of Saudi Arabia

This repository contains scripts to download datasets from the Open Data portal of the Kingdom of Saudi Arabia (KSA). The main script downloads all datasets for a given organization ID and saves them locally.

Directory Structure

.
├── README.md
├── download_all_org.py
├── opendata (optional - parameter in file)
├── requirements.txt
├── open_ksa
│   ├── download_file.py
│   ├── organizations.py
│   ├── get_dataset_resources.py
│   └── get_org_resources.py
└── system-drawing.excalidraw

Functions Overview

  • organizations(): Get the organization information, including the option to write to a target file as a CSV or JSON.
  • get_org_resources(org_id): Retrieves the organization name, organization ID, and dataset IDs for the specified organization.
  • get_dataset_resources(dataset_ids, allowed_exts=['csv', 'xlsx', 'xls'], output_dir='opendata/org_resources', verbose=False): Downloads all data resources for the specified dataset IDs.
  • download_file(session, url, headers, file_path): Downloads a file from the specified URL using the provided session and headers.

Process Flow

graph TD
    subgraph Initialization
        A[Start] --> B[Create SSL Adapter]
        B --> C[Setup Session]
    end

    subgraph Resource Extraction
        C --> D[Extract Organization ID]
        D --> E[Extract Dataset IDs]
    end

    subgraph Directory Setup
        E --> F[Create Directory for Organization]
    end

    subgraph Data Download
        F --> G[Download Dataset Resources]
        G --> H[Save Data Locally]
    end

    subgraph Example - 3_get_dataset_resources.py
        H --> J[Get Organization ID]
        J --> J1[Get All Dataset IDs]
        J1 --> K[Loop Through Dataset IDs]
        K --> L[Download Each Resource]
        L --> M[Save Each Resource Locally]
        M --> N[Run Jupyter Notebook 1_download_data.ipynb]
    end

    N --> I[End]

Installation

To begin collecting data using the open-ksa package, simply install via pip:

pip install open-ksa

Usage

For examples on how to use the package, see the following folders:

These illustrate how to use the package in a script or workbook and examples on how to collect information for one or multiple organizations.

NOTE: For a different organization, you need to update the parameter in the file for the org_id parameter in the function

Release Plan / To DO

  • Create a set of functions to cover the entire API, including:
    • Create a function to get the list of organizations
    • Create a function to get the list of datasets for an organization
    • Create a function to get the list of resources for a dataset
    • Create a function to download a resource
    • Create a function to check the status of a download
  • Create a set of unit tests for the functions
  • Create a set of examples for the functions
  • Create a set of documentation for the functions
  • Move the repository to a PyPi library

Contribution

The contribution process is as follows:

  1. Clone the repository and create a new branch
  2. Make your changes, following the coding style guidelines
  3. Create a pull request with a detailed description of your changes
  4. Wait for your pull request to be reviewed and approved
  5. Once approved, your changes will be merged and available in the main branch

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_ksa-0.1.5.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

open_ksa-0.1.5-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file open_ksa-0.1.5.tar.gz.

File metadata

  • Download URL: open_ksa-0.1.5.tar.gz
  • Upload date:
  • Size: 48.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for open_ksa-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5ebc16572f77805921ceda5583b81400c6c40268885edbcb8efe916f94d31d9c
MD5 d7dc20ceb4ffb34f04942744ede45cf7
BLAKE2b-256 4a49f438d9b5cb0a084f82e368944fdb65b306e18a519bc19df4c8647c24f2d6

See more details on using hashes here.

File details

Details for the file open_ksa-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: open_ksa-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for open_ksa-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1ef1cce6153d2eb002873aabe3d141a1ab2f76b8af4425c87aa0e83768695424
MD5 51a95666793e40ef102185d342126459
BLAKE2b-256 39b9c9ac113528fa9741cdeb6acdbbb0ec4afbdbf9238af6a459782599776af1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page