Created
May 14, 2013 22:45
-
-
Save Verurteilt/5580281 to your computer and use it in GitHub Desktop.
document.py
This file contains 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
from database import CouchDatabase | |
import base64 | |
import urllib2 | |
import json | |
import httplib | |
class CouchDocument(CouchDatabase): | |
def __init__(self, host="http://localhost", port=5984, database="pruebas"): | |
self.host_respaldo = host | |
self.host = host | |
if host.startswith("http://"): | |
self.host =host[7:] | |
elif host.startswith("https://"): | |
self.host = host[8:] | |
CouchDatabase.__init__(self, host=self.host, port=5984) | |
self.database = database | |
def get(self, id="", cb=""): | |
self.cb = cb | |
self.id=id | |
CouchDatabase.send(self, database=self.database, method="GET", cb=self.cb, id=self.id) | |
""" | |
self.id = id | |
url = "%s:%d" % (self.host, self.port) | |
url += "/%s/%s" % (self.database, self.id) | |
request = urllib2.Request(url) | |
contenido = urllib2.urlopen(request) | |
contenido_dict = dict() | |
for total in contenido: | |
contenido_dict.update(json.loads(contenido)) | |
exec "cb(contenido_dict)" | |
return contenido_dict""" | |
def hola(parameter): | |
for i in parameter: | |
print i, parameter[i] | |
c=CouchDocument() | |
c.get(id="mangos", cb=hola) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment