Skip to content

Python library for scraping data sources and creating readable deltas

License

Notifications You must be signed in to change notification settings

simonw/delta-scraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delta-scraper

IN EARLY DEVELOPMENT

PyPI CircleCI Documentation Status License

Python library for scraping data sources and creating readable deltas.

For background, see Scraping hurricane Irma.

Concepts

This library allows you to define scrapers, which are objects that know how to retrieve information from a source (usually a web API, but scrapers can be written to operate against HTML or other formats) and persist that data somewhere as JSON.

When a scraper fetches fresh information it has the ability to compare that data to the old data and use the difference to create a human-readable message.

These capabilities can be combined with a git repository to create a commit log, with human-readable commit messages that accompany a machine-readable diff againts the generated JSON.

See disaster-scrapers and disaster-data for some examples of this pattern in action.

Basic usage

You can define new scrapers by subclassing DeltaScraper. Here's an example which scrapes a list of FEMA shelters.

class FemaShelters(DeltaScraper):
    url = "https://gis.fema.gov/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=FEMA:FEMANSSOpenShelters&maxFeatures=250&outputFormat=json"
    owner = "simonw"
    repo = "disaster-data"
    filepath = "fema/shelters.json"

    record_key = "SHELTER_ID"
    noun = "shelter"

    def fetch_data(self):
        data = requests.get(self.url, timeout=10).json()
        return [feature["properties"] for feature in data["features"]]

    def display_record(self, record):
        display = []
        display.append(
            "  {SHELTER_NAME} in {CITY}, {STATE} ({SHELTER_STATUS})".format(**record)
        )
        display.append(
            "    https://www.google.com/maps/search/{LATITUDE},{LONGITUDE}".format(
                **record
            )
        )
        display.append("    population = {TOTAL_POPULATION}".format(**record))
        display.append("")
        return "\n".join(display)

About

Python library for scraping data sources and creating readable deltas

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages