継続するGETリクエストを実行する疑似モジュールを作成したいと思います(Twitter Streaming APIを使用するモジュールとほぼ同じです)が、誰かが関数を呼び出したいときにすべてのパラメーターを指定する必要はありません。同じGETリクエストを行います。
私のmodule.pyには
class viewResults():
def __init__(self,username,password,keyname,consume):
self.buffer = ""
self.consume = consume
self.conn = pycurl.Curl()
self.conn.setopt(pycurl.USERPWD, "%s:%s" % (username, password))
self.conn.setopt(pycurl.URL, "http://crowdprocess.no.de/"+keyname+"/results")
self.conn.setopt(pycurl.WRITEFUNCTION, self.on_receive)
# self.conn.setopt(pycurl.VERBOSE, 1)
# self.conn.setopt(pycurl.DEBUGFUNCTION, self.debug)
self.conn.perform()
# def debug(self,debug_type,debug_message):
# print 'type: '+str(debug_type)+' message'+str(debug_message)
def on_receive(self, data):
self.buffer += data
if data.endswith("\r\n") and self.buffer.strip():
content = json.loads(self.buffer)
self.consume(content)
self.buffer = ""
そしてindex.pyに私は持っています
from module import viewResults
def consume(content):
print content
viewResults('username','password','keyname',consume)
そのため、パラメーターusername、password、keyname、およびバッファーが有効なJSONデータでいっぱいになったときに呼び出される「consume」関数のみを渡したいと思いました...
何が起こっているのかというと、要求が実際に行われ、VERBOSEがオンの場合、到着するすべてのデータを確認できますが、その「高レベルの消費」関数は何も取得しません...
どうすればこれを達成できますか?ありがとう。