コード例 #1
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
def categorize_email():
    email = json.loads(request.data)
    mail = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    pMail = json.loads(mail[0])
    oldCategory = pMail["category"]
    pMail["category"] = email["category"]
    pMail["categorized"] = True
    emailJSON = json.dumps(pMail, sort_keys=True, indent=4, separators=(",", ": "))
    db.zremrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    db.zadd("mail:%s:inbox" % current_user.user, emailJSON, email["id"])
    db.smove(
        "mail:%s:%s" % (current_user.user, oldCategory),
        "mail:%s:%s" % (current_user.user, pMail["category"]),
        email["id"],
    )
    return "Success"
コード例 #2
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
def delete_category():
    category = json.loads(request.data)["category"]
    newCategory = 1
    mail = db.smembers("mail:%s:%s" % (current_user.user, category))
    print mail
    for emailID in mail:
        # Move email in Redis
        print db.smove(
            "mail:%s:%s" % (current_user.user, category), "mail:%s:%s" % (current_user.user, newCategory), emailID
        )
        # Change category in object
        emailObj = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID)
        pMail = json.loads(emailObj[0])
        pMail["category"] = newCategory
        emailJSON = json.dumps(pMail, sort_keys=True, indent=4, separators=(",", ": "))
        print db.zremrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID)
        print db.zadd("mail:%s:inbox" % current_user.user, emailJSON, emailID)
    return "Success"