Пример #1
0
def send_pending_friends():
    # Protocol 10
    # TODO need to implement remove friend.
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':10'
    packet = json.dumps({
        "Friends": 1,
        "private": priv_key,
        "Sender": username
    })
    message = send([header + ' ' + packet])
    print(message)
    message = message.split(":204 ")
    message = message[1]
    message = json.loads(message)
    f = open("./web/db/messages.json", "r")
    message_db = f.read()
    f.close()
    message_db = json.loads(message_db)
    message_db["pending friends"] = message
    message_db = json.dumps(message_db)
    f = open("./web/db/messages.json", "w")
    f.write(message_db)
    f.close()
Пример #2
0
def add_item(item_name, category, subcategory, groups, type, image, user_tag):
    # Protocol 3
    # TODO may want to add a send all or send some function for own stuff after this call
    username = get_username()
    priv_key = get_priv_key()
    item = {
        "Current Owner": username,
        "Permanent Owner": username,
        "Category": category,
        "Subcategory": subcategory,
        "Name": item_name,
        "Groups": [],
        "Type Info": {},
        "Image": image,
        "User Tags": [],
        "Available": true,
    }
    groups = groups.split(" ")
    for i in groups:
        item["Groups"].append(i)
    item["Type Info"] = type
    user_tag = user_tag.split(" ")
    for j in user_tag:
        item["User Tags"].append(j)
    item_key = create_item_key(item)

    header = '@' + username + ':3'
    packet = json.dumps({item_key: item, "private": priv_key})
    message = send([header + ' ' + packet])
    print(message)
    print(header)
    # item_key is returned for testing purposes
    return item_key
Пример #3
0
def send_message():
    # Protocol 7
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':7'
    packet = json.dumps({"Messages": 1, "private": priv_key})
    message = send([header + ' ' + packet])
    message = message.split(":201 ")
    message = message[1]
    message = json.loads(message)
    f = open("./web/db/friends.json", "r")
    friends_list = f.read()
    friends_list = json.loads(friends_list)
    f.close()
    for i in message:
        item = i
        item = str(item)
        item = item.split("@")
        item = item[1]
        item = item.split(":102 ")
        key = item[0]
        info = item[1]
        info = json.loads(info)
        friend_key = info["Key"]
        friends_list[key] = friend_key
        if info["Step"] == 1:
            add_friend(key, 2)
    f = open("./web/db/friends.json", "w")
    friends_list = json.dumps(friends_list)
    f.write(friends_list)
    f.close()

    return 'I get you all of the messages from your "inbox"'
Пример #4
0
def clear_messagese():
    # Protocol 9
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':9'
    packet = json.dumps({"Messages": -1, "private": priv_key})
    message = send([header + ' ' + packet])
    print(message)
Пример #5
0
def delete_item(item_key):
    # Protocol 2
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':2'
    packet = json.dumps({"Key": [item_key], "private": priv_key})
    message = send([header + ' ' + packet])
    print(message)
    return 'I delete items from your database'
Пример #6
0
def delete_user():
    # Protocol 1
    username = get_username()
    priv_key = get_priv_key()
    pub_key = get_pub_key()
    header = '@' + username + ':1'
    packet = json.dumps({"Delete": 1, "public": pub_key, "private": priv_key})
    message = send([header + ' ' + packet])
    print(message)
Пример #7
0
def send_pending_exchanges():
    # Protocol 11
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':11'
    packet = json.dumps({"Exchanges": 1, "private": priv_key})
    message = send([header + ' ' + packet])
    print("pending ex")
    message = message.split(":203 ")
    message = message[1]
    message = json.loads(message)
    f = open("./web/db/messages.json", "r")
    message_db = f.read()
    message_db = json.loads(message_db)
    f.close()
    message_db["pending exchanges"] = message
    f = open("./web/db/messages.json", "w")
    message_db = json.dumps(message_db)
    f.write(message_db)
    f.close()
Пример #8
0
def send_exchange():
    # Protocol 8
    username = get_username()
    priv_key = get_priv_key()
    header = '@' + username + ':8'
    packet = json.dumps({"Exchanges": 1, "private": priv_key})
    message = send([header + ' ' + packet])
    print("send exchanges")
    print(message)
    message = message.split(":201 ")
    message = message[1]
    message = json.loads(message)
    f = open("./web/db/messages.json", "r")
    message_db = f.read()
    message_db = json.loads(message_db)
    f.close()
    message_db["exchanges"] = message
    f = open("./web/db/messages.json", "w")
    message_db = json.dumps(message_db)
    f.write(message_db)
    f.close()
    return 'I get you all of your exchanges'
Пример #9
0
def change_owner(item_key, friend_name, in_date, out_date):
    # Protocol 6
    # permanent owner agrees to loan item, this protocol is sent
    username = get_username()
    priv_key = get_priv_key()
    f = open("./web/db/friends.json", "r")
    friend_list = f.read()
    f.close()
    friend_list = json.loads(friend_list)

    header = '@' + username + ':6'
    packet = {}
    packet['key'] = item_key
    packet['New Owner'] = friend_name
    packet['public'] = friend_list[friend_name]
    packet['private'] = priv_key
    packet['Schedule']['In'] = in_date
    packet['Schedule']['Out'] = out_date
    packet = json.dumps(packet)

    message = send([header + ' ' + packet])
    print(message)

    return 'I change current owner'