Code Monkey home page Code Monkey logo

bparmentier / pybikes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eskerda/pybikes

1.0 1.0 0.0 1.03 MB

Some python class wrappers to parse info from bike sharing networks across the world. This project is related to CityBikes, as to provide info for the application, thus allowing others to access the same data. It provides the information for the API used by CityBikes

Home Page: http://citybik.es

License: GNU Lesser General Public License v3.0

Python 99.70% Shell 0.30%

pybikes's Introduction

pybikes build

pybikes

pybikes provides a set of tools to scrape bike sharing data from different websites and APIs, thus providing a coherent and generalized set of classes and methods to access this sort of information.

The library is distributed and intended mainly for statistics and data sharing projects. More importantly, it powers the [CityBikes] 1 project, and is composed of a set of classes and a pack of data files that provide instances for all different systems.

Installation

Install directly from GitHub:

pip install git+https://github.com/eskerda/pybikes.git

Or after downloading/cloning the source:

python setup.py install

Usage

>>> import pybikes

# Capital BikeShare instantiation data is in bixi.json file
>>> capital_bikeshare = pybikes.get('capital-bikeshare')

# The instance contains all possible metadata regarding this system
>>> print(capital_bikeshare.meta)
{
    'name': 'Capital BikeShare',
    'city': 'Washington, DC - Arlington, VA',
    'longitude': -77.0363658,
    'system': 'Bixi',
    'company': 'PBSC',
    'country': 'USA',
    'latitude': 38.8951118
}
# The update method retrieves the list of stations
>>> print(len(capital_bikeshare.stations))
0
>>> capital_bikeshare.update()
>>> print(len(capital_bikeshare.stations))
191
>>> print(capital_bikeshare.stations[0])
--- 31000 - 20th & Bell St ---
bikes: 7
free: 4
latlng: 38.8561,-77.0512
extra: {
    'installed': True,
    'uid': 1,
    'locked': False,
    'removalDate': '',
    'installDate': '1316059200000',
    'terminalName': '31000',
    'temporary': False,
    'name': '20th & Bell St',
    'latestUpdateTime': '1353454305589'
}

Some systems might require an API key to work (for instance, Cyclocity). In these cases, the instance factory can take an extra API key parameter.

>>> key = "This is not an API key"
>>> velib = pybikes.get('velib', key)

Note that pybikes works as an instance factory and, choicely, instances can be generated by passing the right arguments to the desired class

>>> from pybikes.cyclocity import BixiSystem
>>> capital_bikeshare = BixiSystem(
        tag = 'foo_tag',
        root_url = 'http://capitalbikeshare.com/data/stations/',
        meta = {'foo':'bar'}
    )

The way information is retrieved can be tweaked using the PyBikesScraper class included on the utils module thus allowing session reusing and niceties such as using a proxy. This class uses [Requests] 2 module internally.

>>> scraper = pybikes.utils.PyBikesScraper()
>>> scraper.enableProxy()
>>> scraper.setProxies({
        "http" : "127.0.0.1:8118",
        "https": "127.0.0.1:8118"
    })
>>> scraper.setUserAgent("Walrus™ v3.0")
>>> scraper.headers['Foo'] = 'bar'
>>> capital_bikeshare.update(scraper)

pybikes's People

Contributors

bparmentier avatar cyrill62 avatar edumucelli avatar eskerda avatar gimco avatar gszathmari avatar hugovk avatar hvergara avatar idupree avatar iomartin avatar javnik36 avatar kawie avatar kevinpcroat avatar madflow avatar manugarri avatar marcoqu avatar micpalmia avatar mikexine avatar neffs avatar njoylab avatar oscar-f avatar r0nd avatar rafaelcanovas avatar thesebas avatar traversaro avatar ustroetz avatar xrmx avatar

Stargazers

 avatar

Watchers

 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.