Created
May 5, 2013 12:13
-
-
Save fontanon/5520672 to your computer and use it in GitHub Desktop.
Unsuccesful try of using Finch library for accessing Proyecto Colibrí groups API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import json | |
from booby import Model, StringField, IntegerField, BooleanField | |
from finch import Collection | |
from tornado import httpclient, ioloop | |
class Party(Model): | |
id = StringField() | |
name = StringField() | |
url = StringField() | |
def parse(self, body, headers): | |
return parse_party(json.loads(body)) | |
def __repr__(self): | |
return 'Party({}/{})'.format(self.name, self.url) | |
class Parties(Collection): | |
model = Party | |
url = 'http://proyectocolibri.es/api/v1/group/' | |
def parse(self, body, headers): | |
return [parse_party(r) for r in json.loads(body)] | |
def parse_party(raw): | |
import pdb; pdb.set_trace() | |
return { | |
'id': int(raw['id']), | |
'name': raw['name'], | |
'url': raw['owner']['login'] | |
} | |
def main(): | |
def on_parties(parties, error): | |
ioloop.IOLoop.instance().stop() | |
if error: | |
raise error | |
for party in parties: | |
print party | |
parties = Parties(httpclient.AsyncHTTPClient()) | |
parties.all(on_parties) | |
ioloop.IOLoop.instance().start() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment