예제 #1
0
def watchfeeds(config_path):
    theconfig = TaConfig(config_path)
    """
    ws=create_connection("ws://localhost:9000/")
    if (ws is None):
        print ("Argggggg")
    ws.send("test111")
    ws.close()
    """

    # run forever - reading feeds and posting to websocket
    while 1:
        for feed in theconfig.feeds:
             # read from feedurl
             try:
                 print "reading from " + feed.url
                 response = urllib2.urlopen(str(feed.url))
                 feeddata = response.read()
                 response.close()

                 try:
                     websockaddress = "ws://" + feed.websocket_host + ":" + feed.websocket_port + "/"
                     print "posting to websocket at " + websockaddress
                     c = create_connection(websockaddress)
                     c.send("test1")
                     c.send(str(feeddata))
                     c.send("test2")
                     c.close()
                 except:
                     print "*** error attempting to post to websocket at " + feed.websocket_host + ":" + feed.websocket_port

             except:
                 print "*** error attempting to read " + feed.url
        time.sleep(10)
예제 #2
0
def streamiter(cookie):
    try:
        with open('lasteid') as f:
            lasteid = f.read()
    except IOError:
        lasteid = "0"
    ws = websocket.create_connection("wss://api.irccloud.com/"
                                     "?since_id=" + lasteid,
                                     header=["Cookie: session=%s" % cookie],
                                     origin="https://api.irccloud.com")
    while 1:
        msg = ws.recv()
        if msg:
            yield json.loads(msg)
예제 #3
0
def streamiter(cookie):
    try:
        with open('lasteid') as f:
            lasteid = f.read()
    except IOError:
        lasteid = "0"
    ws = websocket.create_connection("wss://api.irccloud.com/"
                                     "?since_id=" + lasteid,
                                     header=["Cookie: session=%s" % cookie],
                                     origin="https://api.irccloud.com")
    while 1:
        msg = ws.recv()
        if msg:
            yield json.loads(msg)
예제 #4
0
파일: main.py 프로젝트: BoTranVan/ZeroNet
 def getWebsocket(self, site):
     from lib import websocket
     ws = websocket.create_connection(
         "ws://%s:%s/Websocket?wrapper_key=%s" %
         (config.ui_ip, config.ui_port, site.settings["wrapper_key"]))
     return ws