Exemplo n.º 1
0
def getallbills():
    start = time.time()
    username = request.authorization.username
    passwordinfo = request.authorization.password
    bill_sc = Billschema(many=False)
    data = request.get_json()
    dbtime = time.time()
    flag = checkauthentication(username, passwordinfo)
    dur = (time.time() - dbtime) * 1000
    c.timing("dbconnect", dur)

    if flag == True:
        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')

        bills_schema = Billschema(many=True)
        dbtime = time.time()
        result = Bills.select_user_by_ownerid(owner_id)
        dur = (time.time() - dbtime) * 1000
        c.timing("dbconnect", dur)

        data = bills_schema.dumps(result)

        #File.select_file_by_billid()

        c.incr("getallbillcount")
        dur = (time.time() - start) * 1000
        c.timing("getallbilltime", dur)

        return jsonify(data)
    else:
        return custom_http_code("unauthorized", 401)
Exemplo n.º 2
0
def getallbills():
    username = request.authorization.username
    passwordinfo = request.authorization.password
    bill_sc = Billschema(many=False)
    data = request.get_json()

    flag = checkauthentication(username, passwordinfo)

    if flag == True:
        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')

        bills_schema = Billschema(many=True)

        result = Bills.select_user_by_ownerid(owner_id)

        data = bills_schema.dumps(result)

        #File.select_file_by_billid()

        return jsonify(data)
    else:
        return custom_http_code("unauthorized", 401)
Exemplo n.º 3
0
def daycheck(days):
    username = request.authorization.username
    passwordinfo = request.authorization.password
    flag = checkauthentication(username, passwordinfo)

    if flag == True:
        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')

        bills_schema = Billschema(many=True)
        dbtime = time.time()
        result = Bills.select_user_by_ownerid(owner_id)

        if not result:
            return custom_http_code("no bills for user", 401)

        else:

            sqs = boto3.resource('sqs', region_name='us-east-1')
            #sqs = boto3.resource('sqs',region_name='us-east-1')
            # Get the queue. This returns an SQS.Queue instance
            queue = sqs.get_queue_by_name(QueueName='lambdaQueue')
            message = {}
            message["email"] = username
            message["days"] = days
            message['owner_id'] = owner_id
            message = json.dumps(message)
            response = queue.send_message(MessageBody=message)
            id = response.get('MessageId')
            print(id)
            print(response.get('MD5OfMessageBody'))
            th = threading.Thread(target=threadFunc, args=(username, ))

            # Start the thread
            th.start()
            return custom_http_code('resquest sent to queue' + id, 200)

            # print("helo")
    else:
        return custom_http_code("invalid user")