コード例 #1
0
ファイル: events.py プロジェクト: fsonntag/fridgeninja
def post_event():
    fridge = get_fridge()
    data = request.get_json(force=True)

    user = user_collection.User.find_one({"username": data["username"]})

    if user is None:
        raise ValueError("No user with that name was found!")

    event = event_collection.Event()

    if "timestamp" in data.keys():
        event.timestamp = datetime.datetime.fromtimestamp(data["timestamp"])
    else:
        event.timestamp = datetime.datetime.now()
    transactions = data["transactions"]
    event.transactions = transactions
    event.user = user
    event.save()

    for item, quantity in transactions.items():
        fridge.transact_item(item, quantity)
        fridge.save()
        fridge.reload()

    fridge.save()

    return jsonify(event=event.to_json_type())
コード例 #2
0
ファイル: inventory.py プロジェクト: fsonntag/fridgeninja
def get_inventory():
    fridge = get_fridge()
    return jsonify(inventory=[{"name": item, "quantity": count} for item, count in fridge.content.items()])
コード例 #3
0
ファイル: inventory.py プロジェクト: fsonntag/fridgeninja
def get_item_suggestions():
    fridge = get_fridge()
    return jsonify(suggestions=[item for item, count in sorted(fridge.content.items(), key=lambda (i,c): -int(c))])