Giter Site home page Giter Site logo

pombredanne / data-services-helpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sensiblecodeio/data-services-helpers

0.0 0.0 0.0 423 KB

Python module containing classes and functions that ScraperWiki Data Services often uses

License: BSD 2-Clause "Simplified" License

Python 100.00%

data-services-helpers's Introduction

data-services-helpers

A module containing classes and functions that ScraperWiki Data Services often uses.

Usage

batch_processor

with batch_processor(callback_function(), batch_size=2000) as b:
    # loop to make rows here
    b.push(row)

Here, push on the batch_processor queues items in a list. When the context manager is exited, calls the callback_function with the list of items.

Often used to bundle multiple calls to scraperwiki.sqlite.save when saving data to a database.

update_status

update_status(table_name="swdata", date_column="date")

For updating ScraperWiki dataset status endpoints.

table_name is the SQLite database table name; date_column is the column of that table containing the date the data was recorded.

install_cache

install_cache(expire_after=12 * 3600)

For installing a requests_cache; requires the requests-cache package.

expire_after is the cache expiry time in seconds.

download_url

download_url(url, back_off=True, **kwargs)

GET the content of url using requests.get() and return a file-like object. If back_off=True, then this will retry (with backoff) on failure; otherwise, only one attempt is made. Returns the response.content as a StringIO object.

The **kwargs can be arguments that requests recognises, e.g. headers.

request_url

request_url(url, back_off=True, **kwargs)

As download_url, but returns the response object.

Tests

Run with nosetests.

data-services-helpers's People

Contributors

drj11 avatar fawkesley avatar frabcus avatar pwaller avatar stevenmaude 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.