GithubHelp home page GithubHelp logo

isabella232 / example-earthquake-datastore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ckan/example-earthquake-datastore

0.0 0.0 0.0 6 KB

An example script that sets up and periodically updates a CKAN DataStore table with earthquake data from the NGDS

License: MIT License

Python 100.00%

example-earthquake-datastore's Introduction

example-earthquake-datastore

Note: Requires requests.

An example script that sets up and periodically updates a CKAN DataStore table with earthquake data from the NGDS.

This example demonstrates how to use DataStore tables to push data directly to them rather than automatically import tabular files via the DataPusher. It can be easily be adapted to different data sources.

See it in action at http://demo.ckan.org/dataset/ngds-earthquakes-data

map

Usage

  • Create a virtualenv and install requests:

      virtualenv pyenv
      cd pyenv && source bin/activate
      pip install requests
    
  • Clone this repository:

      mkdir src && cd src
      git clone https://github.com/ckan/example-earthquake-datastore.git
    
  • Define your CKAN URL and API key in the config.ini file.

  • Run the setup command, and write the resulting resource id in your config.ini file:

      python datastore_update.py setup
    
  • Run the update command:

      python datastore_update.py update
    

You probably want to set up this command to run hourly, eg with a cron job:

crontab -e

Add a line like this:

0 0 * * * /path/to/your/pyenv/bin/python /path/to/your/pyenv/src/example-earthquake-datastore/datastore_updater.py update

How it works

When running the setup command we are doing the following things:

  • Creating a new dataset in the remote CKAN instance using the package_create API action.

  • Getting a dump of the remote earthquake data for the past day and extracting the records we want to push to the DataStore.

  • Preparing a mapping of the table fields with the correct field types to ensure they are handled correctly by the DataStore.

  • Pushing the prepared records and the field mapping to a new DataStore resource on the previously created dataset, using the datastore_create API action. Note how we use the id of the previously created dataset. The new resource will be of type datastore and will offer a CSV dump of the data stored in the DataStore.

Once we have this initial setup we can use the update command to periodically request updated earthquake data and push it to our DataStore table using the datastore_upsert API action. As we defined a primary key when creating the DataStore table we can use the upsert method, which will update existing records and insert any new ones.

When accessed via the CKAN frontend, the data can be explored in the grid and map previews powered by Recline, and of course it can be accessed programmatically from other applications using the datastore_search API action.

grid

example-earthquake-datastore's People

Contributors

amercader avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.