本文整理汇总了Python中DB.open_database方法的典型用法代码示例。如果您正苦于以下问题:Python DB.open_database方法的具体用法?Python DB.open_database怎么用?Python DB.open_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB.open_database方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def index():
username = session.get('username')
if not username:
return redirect(url_for('login'))
### Show charts
orderBy = request.args.get('orderBy') #user GET form to tell you how to order the charts
account = session.get('account')
if not orderBy:
orderBy = "roundCost"
chartsData = DB.getCharts(DB.open_database(), orderBy)
UsersData = DB.getUserList(DB.open_database())
return render_template('index.html', chartsData=chartsData, UsersData=UsersData
, account=account, username=username, orderBy=orderBy)
示例2: userRecord
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def userRecord(account):
username = session.get('username')
account = session.get('account')
if not username:
return redirect(url_for('login'))
userRecord=DB.userRecord(DB.open_database(),account)
# your code
return render_template('userInfo.html', userRecord=userRecord, username=username, account=account)
示例3: createAccount
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def createAccount():
if request.method == 'POST':
username = request.form.get('username', '').strip()
account = request.form.get('account', '').strip()
password = request.form.get('password', '').strip()
curTime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
db = DB.open_database()
DB.create_account(db, account, password, username, curTime)
db.commit()
session['username'] = username
session['account'] = account
return redirect(url_for('index'))
示例4: login
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def login():
account = request.form.get('account', '')
password = request.form.get('password', '')
Msg = 'Welcome to 1A2B game filed.<br>Please log in to start a game.' #you can put error message here
if request.method == 'POST': #push login button
db = DB.open_database()
userInfo = DB.getUserInfo(db, account)
pprint.pprint(userInfo)
if password == userInfo[2]:
session['username'] = userInfo[3]
session['account'] = userInfo[1]
session['csrf_token'] = uuid.uuid4().hex
return redirect(url_for('index'))
else:
Msg = 'Please check your account/password'
return render_template('login.html', account=account, msg=Msg)
示例5: challenge
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def challenge():
username = session.get('username')
account = session.get('account')
if not username:
return redirect(url_for('login'))
msg = ''
if request.method == 'POST': #Game over, send you the game result
roundCost = request.form.get('roundCost','').strip()
timeCost = request.form.get('timeCost','').strip()
message = request.form.get('message','').strip()
curTime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
db = DB.open_database()
DB.create_record(db, account, roundCost, timeCost, curTime, message)
db.commit()
return redirect(url_for('index'))
else:
msg = 'Start your game!'
return render_template('challenge.html', msg=msg, account=account)
示例6: beatComputer
# 需要导入模块: import DB [as 别名]
# 或者: from DB import open_database [as 别名]
def beatComputer():
username = session.get('username')
account = session.get('account')
if not username:
return redirect(url_for('login'))
db = DB.open_database()
msg = 'If computer take more than 3 round, you win!'
if request.method == 'POST': #Game start, user send you the number
userNum = request.form.get('userNum','').strip()
ans=int(userNum,10)
ans_a=int(ans/1000)
ans_b=int((ans%1000)/100)
ans_c=int(((ans%1000)%100)/10)
ans_d=int(((ans%1000)%100)%10)
ans_tuple=ans_a,ans_b,ans_c,ans_d
cnt=0
flag=0
record=[]
while cnt<=2 :
guess_a=random.randrange(1,9)
while True:
guess_b=random.randrange(0,9)
if guess_b!=guess_a:
break
while True:
guess_c=random.randrange(0,9)
if guess_c != guess_a and guess_c != guess_a:
break
while True:
guess_d=random.randrange(0,9)
if guess_d!=guess_a and guess_d != guess_b and guess_d != guess_c:
break
cnt_A=0
cnt_B=0
guess_tuple=guess_a,guess_b,guess_c,guess_d
guess=guess_a*1000+guess_b*100+guess_c*10+guess_d
cnt+=1
if ans_a==guess_a and ans_b==guess_b and ans_c==guess_c and ans_d==guess_d :
flag=1
record=record+(guess,'4A0B')
break
else:
if guess_a==ans_a:
cnt_A+=1
if guess_b==ans_b:
cnt_A+=1
if guess_c==ans_c:
cnt_A+=1
if guess_d==ans_d:
cnt_A+=1
pprint.pprint(ans_tuple[0])
for i in range(0,4,1):
for j in range(0,4,1):
if guess_tuple[i]==ans_tuple[j] and i != j:
cnt_B+=1
tmp=str(cnt_A)+'A'+str(cnt_B)+'B'
b=(guess,tmp)
record.append(b)
pprint.pprint(record)
return render_template('beatComputer.html', msg=msg, account=account, data=record, count=len(record) )
else:
return render_template('beatComputer.html', msg=msg, account=account, count=0)