Git Product home page Git Product logo

hap.py's Introduction

hap.py


A cheerful interface for Blockspring APIs

30-second Quick Start

Fire up a Python interpreter.

  1. First, import some things and create a Blockspring instance.

    >>> API_KEY = '<YOUR API KEY HERE>'
    >>> from hap import *
    >>> b = Blockspring(API_KEY)
  2. Let's say we want to do a Google reverse image search. The first thing we need to do is find a block that will do this.

    >>> f = Blockfinder().sort('top').tag('image-processing').fetch(API_KEY).query('reverse')

    What we've done is fetched all blocks with the image-processing tag, sorted by all-time top rating. Then we've searched these results for blocks that have "reverse" in the name.

  3. Now let's create and register our block!

    >>> f.get_block(API_KEY, 0, 'imgsearch').register()
    {'description': u"Enter a URL of an image, get Google's best guess to what that image is, and links to direct matches.", 'schema': [u'image_url'], 'id': u'5a1b66ef208007c51a45fda220dbe8db', 'name': u'Reverse Image Search'}

    At this point our Blockfinder instance still contains more than one block, so we grab the first one (at index 0) and name it imgsearch. Don't forget to register() your block, that's important!

  4. It's time to call it!

    >>> b.imgsearch(image_url='http://cdn.hitfix.com/photos/5621843/Grumpy-Cat.jpg')
    '{"best_search": "grumpy cat", "direct_matches": "[\'http://www.grumpycats.com/\', \'http://en.wikipedia.org/wiki/Grumpy_Cat\', \'http://www.hitfix.com/comedy/the-internet-lies-peter-dinklage-sadly-did-not-take-a-selfie-with-grumpy-cat\', \'http://www.3news.co.nz/entertainment/grumpy-cat-has-hit-her-terrible-twos-2014040611\', \'http://www.3news.co.nz/entertainment/grumpy-cat-sells-out-2013091811\', \'http://www.butterflybeauty.tips/2014/07/tiny-cat-grumpy-cat-and-now-sad-cat.html\', \'http://coffeeticks.my/this-cat-has-gathered-over-5-million-likes-on-facebook/\']"}'

Yes, it was really that easy.

Usage

You can safely do from hap import *. This imports the three classes Block, Blockfinder, and Blockspring.

hap.py's People

Contributors

willyg302 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.