def eod_process(): global db, cur, t, gv_contract db = _connect_db() cur = db.cursor() forced_close() open_cont() close_cont() return_fee() settle_cont() achieve_cont() balance2date(datetime.date.today() - datetime.timedelta(1)) update_feerate() _update_contract(db) cur.close() db.close() t = threading.Timer(EOD_INTERVAL, eod_process) t.start() print >>sys.stderr, time.strftime("%d_%H:%M", time.localtime(time.time())), "EOD Process Finished."
class g: db = _connect_db() cur = db.cursor()
def before_request(): if request.method == "POST": token = session.pop('_csrf_token', None) if not token or token != request.form.get('_csrf_token'): abort(403) g.db = _connect_db()
def before_first_request(): g.db = _connect_db() _update_contract(g.db) _start_eod_sevice() _start_twt_sevice()
return {'msg':"Have more activities before withdraw.",'category':'err'} else: cur.execute("insert into btc_action(action,account1,address,amount,type,input_dt) values ('sendfrom',%s,%s,%s,'W',NOW());" ,(email,btc_add,amount)) db.commit() cur.close() return {'msg':"Withdraw "+amount+" Btc Successfully",'category':'suc'} else: return {'msg':"Password is not correct.",'category':'err'} def _dercode(code): try: str = code.split('~') referrer = base64.urlsafe_b64decode(str[0].encode('ascii','ignore')) d_email = base64.urlsafe_b64decode(str[1].encode('ascii','ignore')) return dict(referrer=referrer,email=d_email) except Exception: return dict(referrer=0,email='') def _enrcode(user_id,email): a_user = base64.urlsafe_b64encode(str(user_id)) a_email = base64.urlsafe_b64encode(email) return a_user + '~' + a_email if __name__ == "__main__": from _db import _connect_db db = _connect_db() add_scoupon(db,1,0.1,'hello') add_scoupon(db,1,0.1,'hello')