-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.py
30 lines (24 loc) · 1.06 KB
/
misc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import g
def get_misc(user, custom_from=1, row_per_page=69):
g.cur.execute('SELECT transaction_time, transaction_type, amount, payload FROM misc_tx WHERE user_id=%s LIMIT %s OFFSET %s;',
(user, row_per_page, (custom_from-1)*row_per_page))
return g.cur.fetchall()
def apply_misc(user, transaction_type, amount, payload):
apply_misc_cron(user, transaction_type, amount, payload, g.cur)
def apply_misc_cron(user, transaction_type, amount, payload, cur):
if amount == 0:
return False
elif amount < 0:
try:
cur.execute('SELECT balance FROM users WHERE id=%s', (user,))
balance = cur.fetchone()[0]
if balance < -amount:
return False
except:
return False
###
cur.execute('INSERT INTO misc_tx (user_id, transaction_type, amount, payload) VALUES (%s, %s, %s, %s);',
(user, transaction_type, amount, payload))
cur.execute('UPDATE users SET balance=balance+%s WHERE id=%s',
(amount, user))
return True