예제 #1
0
def handle_realtime_connect(keyword):
    print('received keyword: ' + keyword)
    # emit('data_transfer', "json.dumps(data)", broadcast=True)
    pubsub = redis.pubsub()
    pubsub.subscribe('tweets_processed')
    tweets = pubsub.listen()
    while True:
        try:
            message = tweets.next()

            processed_tweet = message.get('data')
            if not processed_tweet:
                continue
            try:
                data = pickle.loads(processed_tweet)
            except TypeError, e:
                continue
            if not isinstance(data, dict):
                continue

            if data["text"] and data["lon"] and data["lat"]:
                if keyword in data["text"]:
                    emit('data_transfer', json.dumps(data))

        except Exception, e:
            emit('die1', e, broadcast=True)
            pubsub.unsubscribe('tweets_processed')
            print e
            return
예제 #2
0
def handle_realtime_connect(keyword):
    print ("received keyword: " + keyword)
    pubsub = redis.pubsub()
    pubsub.subscribe("sentiment-tweet")
    tweets = pubsub.listen()
    while True:
        try:
            message = tweets.next()
            raw_tweet = message.get("data")
            if not raw_tweet:
                continue

            tweet = None
            if str(raw_tweet)[0] == '"' or str(raw_tweet)[0] == '"':  # sns message has backslash in it
                tweet = json.loads(str(raw_tweet.decode("string_escape"))[1:-1])
            else:
                tweet = json.loads(str(raw_tweet))
            if not isinstance(tweet, dict):
                continue

            text = tweet.get("text")
            lon = tweet.get("lon")
            lat = tweet.get("lat")
            sentiment_score = tweet.get("sentiment_score")
            data = {"text": text, "lon": lon, "lat": lat, "sentiment_score": sentiment_score}
            if text and lon and lat and data:
                if keyword in text:
                    emit("data_transfer", json.dumps(data))
        except Exception, e:
            emit("die", e, broadcast=True)
            pubsub.unsubscribe("twitter_raw")
            print e
            return
예제 #3
0
def event_stream(item_id=None):
    channel = 'list_view' if item_id is None else 'list_view_{0}'.format(item_id)
    pubsub = redis.pubsub()
    pubsub.subscribe(channel)

    for itm in pubsub.listen():
        yield itm
예제 #4
0
파일: backend.py 프로젝트: donny/elmutt
 def __init__(self):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(REDIS_CHAN)
     redis_url = urlparse.urlparse(REDIS_URL)
     redisco.connection_setup(
         host=redis_url.hostname, port=redis_url.port, password=redis_url.password)
예제 #5
0
def callback():
        global xref
	#r = redis.client.StrictRedis()
	sub = redis.pubsub()
	sub.subscribe(fromRedisIn)
	while True:
		for m in sub.listen():
                        xref = float (m['data']) #'Recieved: {0}'.format(m['data'])
			print "xref: ", xref
예제 #6
0
def receiveInformations():
    import redis
    redis = redis.StrictRedis()

    pubsub = redis.pubsub()
    pubsub.psubscribe('stats.*')

    for message in pubsub.listen():
        if message['type'] == 'pmessage':
            statistics = json.loads(message['data'])
예제 #7
0
def getWordCount(msg):
    pubsub = redis.pubsub()
    pubsub.subscribe('word_count')
    message = pubsub.listen()
    while True:
        try:
            count = message.next().get('data')
            emit('wordcount_s2c', count)
            # print count
        except Exception, e:
            emit('die2', e, broadcast=True)
            pubsub.unsubscribe('word_count')
            print e
            return
예제 #8
0
def receiveInformations():
    import redis
    redis = redis.StrictRedis()

    pubsub = redis.pubsub()
    pubsub.psubscribe('extra.lookupinfos')

    for message in pubsub.listen():
        if message['type'] == 'pmessage':
            user = json.loads(message['data'])
            user_id = user['id_str']
            screen_name = user['screen_name']

            print "Adding information for %s => %s (STREAM)" % (user_id, screen_name)
            database['user:%s' % user_id] = message['data']
예제 #9
0
def test():
    pubsub = redis.pubsub()
    pubsub.subscribe('tweets_processed')
    tweets = pubsub.listen()
    num=0
    while True:
        print "test:",num
        num+=1
        message = tweets.next()
        processed_tweet = message.get('data')
        if not processed_tweet:
            continue
        try:
            processed_tweet_dict = pickle.loads(processed_tweet)
        except TypeError, e:
            continue
        if not isinstance(processed_tweet_dict, dict):
            continue
        # print processed_tweet_dict['id']
        data_filter(processed_tweet_dict)
def main():
    """
    main entry point for the program
    The return value will be the returncode for the program
    """
    _initialize_stderr_logging()
    log = logging.getLogger("main")
    log.info("program starts")

    args = _parse_commandline()

    redis = _create_redis_connection()
    subscriber = redis.pubsub()
    subscriber.subscribe(args.notification_channel)
    for message in subscriber.listen():
        if message["type"] == "subscribe": 
            log.info("subscribed to {0}".format(message["channel"]))
        elif message["type"] == "message":
            _process_message(args, redis, message)
        else:
            log.error("Unknown message {0}".format(message))

    log.info("program completes return code = 0")
    return 0
예제 #11
0
파일: app.py 프로젝트: mimaczek/Zawody
 def __init__(self):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(REDIS_CHAN)
예제 #12
0
파일: library.py 프로젝트: dtangster/cs157a
 def __init__(self):
     self.clients = list()
     self.broadcaster = redis.pubsub()
     self.broadcaster.subscribe(DATABASE_BROADCASTER)
예제 #13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import redis

from socketIO_client import SocketIO

REDIS_CONFIG = {
    'host': 'localhost',
    'port': 6379,
    'db': 0,
    }

redis = redis.StrictRedis(**REDIS_CONFIG)
pubsub = redis.pubsub(ignore_subscribe_messages=True)
pubsub.subscribe('temperature.value')

socket = SocketIO('localhost', 5000)

for notification in pubsub.listen():
    print notification['channel']
    print notification['data']
    socket.emit('temperature', {'data': notification['data']})
예제 #14
0
import redis
import time
import json
#run this on python 3.6 pod

# just a simple subscribe to see if things are working as expected

config = json.load(open('./config.json'))
REDIS_HOST = config['redis_host']
REDIS_HOST_PORT = config['redis_host_port']
redis = redis.Redis(host=REDIS_HOST, port=REDIS_HOST_PORT)

tweetstream = redis.pubsub()
tweetstream.subscribe("stream")

if __name__ == '__main__':

    while True:
        message = tweetstream.get_message()
        if message:
            print("Tweets published")
            print(message["data"])
 def __init__(self, redis, request_channel):
     self.r = redis
     self.p = redis.pubsub(ignore_subscribe_messages=True)
     self.request_channel = request_channel
 def __init__(self):
     self.ps_obj = redis.pubsub()
     self.ps_obj.subscribe(commHMI)
예제 #17
0
 def __init__(self, redis_chan):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(redis_chan)
예제 #18
0
파일: app.py 프로젝트: accumsan/py
 def __init__(self, channel):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(channel)
예제 #19
0
#!/usr/bin/env python

import redis
import time
import os
import json

redis = redis.StrictRedis(host='localhost', port=6379, db=0)
channel = redis.pubsub()

queue = os.environ.get('REDIS_ANIMATION_QUEUE')
process = {}
process['moduleName'] = 'mario.py'
# process['moduleName'] = 'scanning-pixel.py'
redis.publish(queue, json.dumps(process))
예제 #20
0
파일: app.py 프로젝트: ralmn/CMAsk
 def __init__(self):
     self.clients = {}
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(settings.REDIS_CHAN)
예제 #21
0
def valuebyHour(date):
    daydata = sortbyDay(date)
    count = 0
    hourvalue = []
    sendervalue = {}
    recvervalue = {}
    if daydata is not None:
        count = daydata['count']
        hourdata = daydata['data']
        for h in hourdata:
            hourvalue.append(len(h['rockets']))
            sender = 'sender_id'
            recver = 'recver_id'
            rocket = h['rockets']
            if len(rocket) != 0:
                sendervalue = sortNames(rocket, sender, sendervalue)
                recvervalue = sortNames(rocket, recver, recvervalue)
        return (count, hourvalue, sendervalue, recvervalue)
    else:
        return None


# 用于获取弹幕信息和火箭信息的redis 订阅频道
redis = redis.StrictRedis(password='******')
chatcast = redis.pubsub()
chatcast.subscribe('chatinfo')

rocketcast = redis.pubsub()
rocketcast.subscribe('rocketinfo')
예제 #22
0
 def __init__(self):
     self.clients = []
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe('chat')
예제 #23
0
#!/usr/bin/env python


from real_datas_test import fake_planes
from libPyAirwaves.structs import AdsbType
import time
import config as cfg
import redis
import json

DELAY_MESSAGES = 2  # second

redis = redis.from_url(cfg.REDIS_URL)
pubsub = redis.pubsub()
pubsub.subscribe("room:vehicles")

print("Sending messages...")

try:
    sample = "MSG,3,1,1,field_4,1,2019/02/25,20:49:58.331,2019/02/25,20:49:58.361,,field_11,,,field_14,field_15,,field_17,0,,0,0"
    foo = sample.split(",")

    # "addr": "000000", "idInfo": "LOLK293", "alt": 23000, "aSquawk": "1337"
    for coords in fake_planes["planeA"]["path"]:
        msg = foo
        msg[4] = fake_planes["planeA"]["idInfo"]
        msg[11] = str(fake_planes["planeA"]["alt"])
        msg[14] = str(coords[1])
        msg[15] = str(coords[0])
        msg[17] = fake_planes["planeA"]["aSquawk"]
        adsb_msg = AdsbType()
예제 #24
0
 def __init__(self):
     self.clients = []
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe('chat')
예제 #25
0
    global current_uuid, player
    if player is not None and player.filename is None:
        uuid = current_uuid
        current_uuid = None
        return uuid
    else:
        return False


def control_callback(message):
    global player
    if player is not None and player.filename is not None:
        playback_pause()


p = redis.pubsub(ignore_subscribe_messages=True)
p.subscribe(musicacontrol=control_callback)


def status_update():
    global player
    if player is None:
        return
    redis.set(
        "musicastatus",
        json.dumps({
            "paused": player.paused,
            "time": player.time_pos or 0,
            "length": player.length or 0
        }))
예제 #26
0
#!/usr/bin/env python

import redis
import time
import os
import json

redis = redis.StrictRedis(host='localhost', port=6379, db=0)
channel = redis.pubsub()

queue = os.environ.get('REDIS_ANIMATION_QUEUE')
process = {}
process['moduleName'] = 'kit.py'
# process['moduleName'] = 'gol-block-switch.py'
# process['moduleName'] = 'gol-acorn.py'
# process['moduleName'] = 'gol-pent.py'
# process['moduleName'] = 'gol-gosper-gun.py'
redis.publish(queue, json.dumps(process))
예제 #27
0
 def __init__(self):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(REDIS_CHAN)
     self.firebase = firebasin.Firebase("https://gamim.firebaseio.com/")
예제 #28
0
파일: websocket.py 프로젝트: Ell/Siri
 def __init__(self, rchan):
     self.clients = []
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(rchan)
예제 #29
0
        if not raw_tweet:
            continue

        tweet = json.loads(raw_tweet)

        # Sometimes we just get back spurious data, like integers and stuff
        if not isinstance(tweet, dict):
            continue

        # Data extraction
        tweet_body = tweet.get('text')
        user = tweet.get('user', {})
        username = user.get('screen_name')
        name = user.get('name')

        # Data presentation
        if tweet_body and name and username:
            log_tweet(username, name, tweet_body)


if __name__ == '__main__':
    try:
        redis = redis.StrictRedis(host='localhost', port=6379, db=0)
        pubsub = redis.pubsub()
        pubsub.subscribe('twitter_raw')
        tweets = pubsub.listen()
        consume_subscription(tweets)

    except KeyboardInterrupt:
        print "\nBye!"
예제 #30
0
 def __init__(self):
     self.clients = list()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(REDIS_CHAN)
예제 #31
0
 def __init__(self):
     self.tables = dict()
     self.pubsub = redis.pubsub()
     self.pubsub.subscribe(REDIS_CHAN)