Exemplo n.º 1
0
def get_rewards(user, _type=4):
    print user_info(user)
    try:
        data = user.get("menu/rewardbox")
        notice_ids = [x.id for x in data.rewardbox_list.rewardbox if x.type != _type]
        point = sum(x.point for x in data.rewardbox_list.rewardbox if x.type == 4)
        user.logger.debug('礼品包: 草纸 %s个, 其他%s个' % (point, len(notice_ids)))
        while notice_ids:
            _l, notice_ids = notice_ids[:19], notice_ids[19:]
            user.get_rewards(_l)
    except Exception as e:
        print e.message
Exemplo n.º 2
0
def user_tag_remove(username):
    """
    Delete SINGLE tag associate with user
    :param username:
    :return:
    """
    if not auth(  # authenticate user
            app.config['SECRET_KEY'],
            request,
            username
    ):
        return response_unauthorised()
    try:
        assert username == request.view_args['username']

        try:
            tag = request.json['user_tag']
            tags = user.user_info(username)['user_tags']
            new_tags = tags.replace(tag, '')
            new_tags = util.tag_validator(new_tags)  # format tags
            user.update_user(username, tags=new_tags)
        except KeyError:
            return response_invalid()

        response_json = json_dict({"user_tags": new_tags}, indent=4)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
Exemplo n.º 3
0
def user_tag_add(username):
    """
    Add new tags to a user
    :param username:
    :return:
    """

    try:
        assert username == request.view_args['username']

        if not auth(  # authenticate user
                app.config['SECRET_KEY'],
                request,
                username
        ):
            return response_unauthorised()

        json_request = request.json

        # Check user_tags parameter exists
        try:
            new_tags = json_request['user_tags']
            current_tags = user.user_info(username)['user_tags']
            separate = "" if current_tags == "" else ","  # stop incorrect commas at start of comma separated lists
            current_tags = current_tags + separate + new_tags.replace(" ", "")  # remove whitespace in tags
            user.update_user(username, tags=current_tags)
        except:
            return response_invalid()

        response_json = json_dict({"user_tags": current_tags}, indent=4)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
Exemplo n.º 4
0
def get_user(username):
    assert username == request.view_args['username']

    if not verify.verify_str(username):
        return response_invalid()
    try:
        response_json = json_dict(
            user.user_info(username),
            indent=4,
            default=str
        )
    except:
        return response_notFound()

    return Response(response_json, status=success_code, mimetype='application/json')
Exemplo n.º 5
0
def user_tag_get(username):
    """
    Retrive tags associated with user
    :param username:
    :return:
    """
    try:
        assert username == request.view_args['username']

        tags = user.user_info(username)['user_tags']

        if not isinstance(tags, str):
            return response_invalid()

        response_json = json_dict({"user_tags": tags}, indent=4)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_notFound()
Exemplo n.º 6
0
import user

in_id = input("Enter the id ")
new_data = user.user_info(in_id)
if new_data == 0:
    print("user not found ")
else:
    print("{0.name}\t{0.id}\t{0.books}".format(new_data))
Exemplo n.º 7
0
print("*" * 68)
print("-" * 68)
print("\n" + " " * 25 + "Welcome to Library" + "\n" + " " * 25)
print("-" * 68)
print("*" * 68)

while True:
    op = int(
        input(
            "\nChoose the operation:\n1.Issue book\n2.Return book\n3.Get book list\n4.Get book info: "
        ))

    if op == 1:
        print("\nScan the user id: ")
        uid = rfid_data.rfid_data()
        new_data = user.user_info(uid)
        if new_data == 0:
            print("User not found ")
            continue
        else:
            print("Name: {0.name}\tId: {0.id}\tBooks: {0.books}".format(
                new_data))

        while True:
            print("Scan book id: ")
            bid = rfid_data.rfid_data()
            book = hello.get_book(bid)
            if book == 0:
                print("Book not found ")
            else:
                print(