def test_timeuntil(): now = datetime(2010, 4, 12, 12, 30, 0) future = datetime(2010, 5, 15, 1, 50, 0) # basic assert time_until(future, now) == "1 month and 2 days" # count assert time_until(future, now, count=3) == "1 month, 2 days and 13 hours"
def allowed(db, nick, nick_vote): time_restriction = 3600.0 db.execute(voter_table.delete().where((time.time() - voter_table.c.timestamp) >= time_restriction)) db.commit() check = db.execute( select([voter_table.c.timestamp]) .where(voter_table.c.voter == nick.lower()) .where(voter_table.c.votee == nick_vote.lower()) ).scalar() if check: print(check) if time.time() - check >= time_restriction: db.execute("""INSERT OR REPLACE INTO karma_voters( voter, votee, timestamp) values(:voter, :votee, :timestamp)""", {'voter': nick.lower(), 'votee': nick_vote.lower(), 'timestamp': time.time()}) db.commit() return True, 0 else: return False, timeformat.time_until(check, now=time.time() - time_restriction) else: db.execute("""INSERT OR REPLACE INTO karma_voters( voter, votee, timestamp) values(:voter, :votee, :timestamp)""", {'voter': nick.lower(), 'votee': nick_vote.lower(), 'timestamp': time.time()}) db.commit() return True, 0
def allowed(uid): """ checks if a user is allowed to vote, and keeps track of voters """ global voters # clear expired voters for _uid, _timestamp in voters.items(): if (time.time() - _timestamp) >= TIME_LIMIT: del voters[_uid] if uid in voters: last_voted = voters[uid] return False, timeformat.time_until(last_voted, now=time.time() - TIME_LIMIT) else: voters[uid] = time.time() return True, 0
def allowed(db, nick, nick_vote): time_restriction = 3600.0 db.execute(voter_table.delete().where( (time.time() - voter_table.c.timestamp) >= time_restriction)) db.commit() check = db.execute( select([voter_table.c.timestamp ]).where(voter_table.c.voter == nick.lower()).where( voter_table.c.votee == nick_vote.lower())).scalar() if check: print(check) if time.time() - check >= time_restriction: db.execute( """INSERT OR REPLACE INTO karma_voters( voter, votee, timestamp) values(:voter, :votee, :timestamp)""", { 'voter': nick.lower(), 'votee': nick_vote.lower(), 'timestamp': time.time() }) db.commit() return True, 0 else: return False, timeformat.time_until(check, now=time.time() - time_restriction) else: db.execute( """INSERT OR REPLACE INTO karma_voters( voter, votee, timestamp) values(:voter, :votee, :timestamp)""", { 'voter': nick.lower(), 'votee': nick_vote.lower(), 'timestamp': time.time() }) db.commit() return True, 0