コード例 #1
0
ファイル: thrifty.py プロジェクト: prakharsharma/thrifty
def genUserId(email):
    uid = (email is None and [None] or [(utils.genIdentifier(
                    ["%d" % utils.genRandom(), email, "%d" %
                    utils.timestamp()]))])[0]
    print "[DBG] uid = %d" % uid
    return uid
コード例 #2
0
ファイル: dbWorker.py プロジェクト: prakharsharma/thrifty
 def newBill(self, userCookie, amount, category, date,
         reportedBy, reportedAt = utils.timestamp(False),
         billType = 'individual', participants = [],
         tags = [], description = None, userAmounts = [],
         emails = []):
     cursor = self.__conn.cursor()
     try:
         uid = self.getUser(ck = userCookie)['_id']
         ppl = participants
         if len(ppl) == 0:
             ppl.append(reportedBy)
         bill_id = utils.genIdentifier(["%d" % utils.genRandom(),
                 "%d" % date, "%d" % reportedBy, category])
         cursor.execute("""
         INSERT INTO """ + DbWorker.dbCfg['table.bill'] + """ 
          VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
         """ , (bill_id,
         amount, category,
         date, reportedAt, reportedBy, billType,
         ",".join([str(x) for x in ppl]),
         utils.joinOrNone(tags), description))
         utils.dbgMsg("Inserted %d rows to table %s" %
                 (cursor.rowcount, DbWorker.dbCfg['table.bill']),
                 DbWorker.globalCfg['debug'],
                 DbWorker.globalCfg['debug.info'], __name__,
                 DbWorker.currFrame.f_lineno,
                 DbWorker.currFrame.f_code.co_filename)
         amnts = userAmounts
         if (len(amnts) == 0):
             amnts.append(amount)
         if (len(ppl) != len(amnts) and len(ppl) != len(emails)):
             raise LogicalError("""#ppl and #amount #emails should be
                     same.
                      ppl = [%s], amnts = [%s], emails = [%s]
                     """ % (",".join(["%d" % x for x in ppl]),
                     ",".join(["%f" % x for x in amnts])),
                     ",".join(emails))
         idAmntComb = map(lambda x, y: (x, y), ppl, amnts)
         idAMntEmailComb = map(lambda (x, y), z: (x, y, z), idAmntComb,
                 emails)
         for uid, amt, email in idAMntEmailComb:
             uid = int(uid)
             amt = float(amt)
             try:
                 self.getUser(uid = uid)
             except (BadArgs, RecordNotFound):
                 tstmp = utils.timestamp(False)
                 tmpCookie = utils.genIdentifier(["%d" %
                         utils.genRandom(), "%d" % uid, "%d" %
                         tstmp])
                 self.userLogin(userId = uid,
                         userCookie = tmpCookie, lastSeen = tstmp,
                         email = email, openid = None,
                         firstName = None, lastName = None,
                         cellPhone = None, memberSince = tstmp,
                         uType = 'auto')
             cursor.execute("""
             INSERT INTO """ + DbWorker.dbCfg['table.expense'] +"""
              VALUES(%s, %s, %s, %s, %s, %s)
             """ , (bill_id,
             uid, amt, date, category, utils.joinOrNone(tags)))
     except:
         raise
     finally:
         self.__conn.commit()
         cursor.close()
コード例 #3
0
ファイル: thrifty.py プロジェクト: prakharsharma/thrifty
def getLoggedCookie(email):
    print "[DBG] email = " + email
    val = "%d" % utils.genIdentifier([email, "%d" % utils.timestamp()])
    print "[DBG] loggedInCookie value = " + val
    return val
コード例 #4
0
ファイル: dbWorker.py プロジェクト: prakharsharma/thrifty
                'mm/dd/yyyy')
        return rec

    def userIdFromCookie(self, cookie):
        user = self.getUser(ck = cookie, uid = None)
        return user['_id']

    def junk(self):
        pass

if __name__ == "__main__":
    worker = DbWorker()
    email = raw_input("Email: ")
    ck = raw_input("Cookie: ")
    email = (len(email) and [email] or [None])[0]
    ck = (len(ck) and [long(ck)] or [utils.genIdentifier([email, "%d" %
                utils.timestamp()])])[0]
    print "Cookie = %d" % ck
    uid = (email is None and [None] or [(utils.genIdentifier(
                    ["%d" % utils.genRandom(), email, "%d" %
            utils.timestamp()]))])[0]
    worker.userLogin(uid, ck, utils.timestamp(False), email,
            "xyz__nnnn", "Prakhar",
            "Sharma", "631-885-4602", utils.timestamp(False), 'manual')
    cont = raw_input("wanna report an expense (y/n): ")
    if cont == "y" or cont == "Y":
        amnt = float(raw_input("bill amount: "))
        catg = raw_input("bill category: ")
        uid = worker.userIdFromCookie(ck)
        if uid is None:
            sys.stderr.write("User for cookie %s not present" % ck)
            sys.exit(1)