Ejemplo n.º 1
0
    def __init__(self, queueName='searcherqueue', dbName=Credential.dbName):
        # Initialize Database
        self.queueName = queueName
        self.dbName = dbName
        self.count = 0

        try:
            # Initialize Queuing system

            self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1'))
            self.channel = self.connection.channel()
            self.channel.queue_declare(queue=self.queueName)
            self.db = CouchConnection(dbName=self.dbName)

        except Exception as err:

            print 'Error Occured in Searchqueue %s' % err
        self.start()
Ejemplo n.º 2
0
    def __init__(self, queueName='streamqueue', dbName=Credential.dbName):
        self.queueName = queueName
        self.dbName = dbName
        self.count = 0

        try:

            self.connection = pika.BlockingConnection(
                pika.ConnectionParameters(host='127.0.0.1'))
            self.channel = self.connection.channel()
            self.channel.queue_declare(queue=self.queueName)
            self.db = CouchConnection(dbName=self.dbName)
            self.streamDB = CouchConnection(dbName="stream_db")

        except Exception as e:
            print 'CouchdbError: %s' % e

        self.startStreaming()
Ejemplo n.º 3
0
class StreamQueue:
    def __init__(self, queueName='streamqueue', dbName=Credential.dbName):
        self.queueName = queueName
        self.dbName = dbName
        self.count = 0

        try:

            self.connection = pika.BlockingConnection(
                pika.ConnectionParameters(host='127.0.0.1'))
            self.channel = self.connection.channel()
            self.channel.queue_declare(queue=self.queueName)
            self.db = CouchConnection(dbName=self.dbName)
            self.streamDB = CouchConnection(dbName="stream_db")

        except Exception as e:
            print 'CouchdbError: %s' % e

        self.startStreaming()

    def callback(self, ch, method, properties, raw_data):

        print '[%s] received' % self.count

        try:
            tweet = json.loads(raw_data)
            flag = self.db.save(
                tweet)  # save to tweets pool that includes history tweets
            self.streamDB.save(tweet)  # save to fresh tweets pool
            if flag is None:
                self.count = self.count + 1
                print 'done'

            ch.basic_ack(delivery_tag=method.delivery_tag)

        except Exception as err:
            print 'problem occured in callBack %s' % err

    def startStreaming(self):
        self.channel.basic_qos(prefetch_count=1)
        self.channel.basic_consume(self.callback, queue=self.queueName)
        print 'Streaming queue building completed'
        self.channel.start_consuming()
Ejemplo n.º 4
0
class SearcherQueue:

    def __init__(self, queueName='searcherqueue', dbName=Credential.dbName):
        # Initialize Database
        self.queueName = queueName
        self.dbName = dbName
        self.count = 0

        try:
            # Initialize Queuing system

            self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1'))
            self.channel = self.connection.channel()
            self.channel.queue_declare(queue=self.queueName)
            self.db = CouchConnection(dbName=self.dbName)

        except Exception as err:

            print 'Error Occured in Searchqueue %s' % err
        self.start()

    def callback(self, ch, method, properties, tweet):

        print '[%s] totalSaved' % self.count

        try:
            flag = self.db.save(json.loads(tweet))

            if flag is None:
                self.count = self.count + 1
                print 'done'

        except Exception as err:
            print 'problem occured in search callBack %s' % err

        ch.basic_ack(delivery_tag=method.delivery_tag)

    def start(self):
        self.channel.basic_qos(prefetch_count=1)
        self.channel.basic_consume(self.callback, queue=self.queueName)
        print "Rabbit Start, searqueue"
        self.channel.start_consuming()
Ejemplo n.º 5
0
 def __init__(self):
     self.database = CouchConnection()
     self.activeUser = dict()
Ejemplo n.º 6
0
class Server:
    def __init__(self):
        self.database = CouchConnection()
        self.activeUser = dict()

    def loginUser(self, user_id):

        return self.database.checkUser(user_id)

    def getActiveUser(self):
        return self.activeUser.keys()

    def registerSession(self, userID):
        recvMsg = self.database.getUserInfo(userID)
        print 'recv', recvMsg

        if recvMsg['code'] == 200:
            userInfo = recvMsg['message']
            userID = userInfo['id']

            if userID in self.activeUser:
                return {'code': 409, 'message': 'user has already activated.'}

            self.activeUser[userID] = UserSession(userInfo)
            sessionCode = self.activeUser[userID].getCurSession()

            sendMsg = {
                'code': 200,
                'message': {
                    'user': userInfo['name'],
                    'sessionCode': sessionCode
                }
            }

        else:
            sendMsg = recvMsg

        return sendMsg

    def updateHR(self, userID, heartRate):

        if userID not in self.activeUser:
            return False

        try:

            status = self.activeUser[userID].updateHR(heartRate)

            if status == 'timeReached':
                sessionCode = self.activeUser[userID].getCurSession()
                sessionData = self.activeUser[userID].getSessionData()

                userInfo = self.activeUser[userID].getUserInfo()
                self.database.saveSession(userInfo, sessionCode, sessionData)
                return {'message': status}

            return {'message': status}

        except Exception:
            return False

    def getUserLatestHR(self, userID):

        try:
            hr, hr_count = self.activeUser[userID].getLatestHR()

            return hr, hr_count
        except KeyError:
            return False

    def getAllUsers(self):

        response = self.database.getUsers()
        if response['code'] == 200:
            list = response['message']

            return {'code': 200, 'message': list}
        else:
            return {'code': 500, 'message': response['message']}

    def createUser(self, userInfo):
        response = self.database.createUser(userInfo)

        if response['code'] == 200:
            return {'code': 200, 'message': response['message']}
        else:
            return response

    def active_user(self, userID):

        if userID in self.activeUser:
            self.activeUser[userID].activeSession()

            return True, 'user ' + userID + ' activated.'

        else:
            return False, 'user not found.'

    def deactiveUser(self, userID):

        if userID in self.activeUser:
            del self.activeUser[userID]

            return True, 'removed'

        return False, 'not found'

    def getUserDetail(self, userID):

        status = self.database.getUserDetail(userID)
        isSuccessful = status[0]

        if isSuccessful is True:
            userDetail = status[1]
            return True, userDetail

        return False, {}
Ejemplo n.º 7
0
'''
Team: Team 22
City: Melbourne
Name: Yanjun Peng (906571)
	   Na Chang (858604)
	   Zepeng Dan (933678)
	   Junhan Liu (878637)
	   Peishan Li (905508)
'''
import Credential
import tweepy
from CouchConnection import CouchConnection

db = CouchConnection(dbName='stalker')
api = tweepy.API(Credential.getTwitterAuth("Stalker"), wait_on_rate_limit=True)

count = 0


def isIn(tweetCoord):
    print tweetCoord

    ausBox = Credential.ausBox

    if ausBox[0][0] < tweetCoord[0][0] and ausBox[0][1] < tweetCoord[0][1] and ausBox[2][0] > \
            tweetCoord[2][0] and ausBox[2][1] > tweetCoord[2][1]:
        return True
    else:
        return False