Correction passage mysql

This commit is contained in:
guimoz 2017-01-31 14:34:59 +01:00
parent 9e40c297b4
commit 9eb47a7c26

View file

@ -6,7 +6,7 @@ from flask import Flask, request, g, redirect, url_for, \
from functools import wraps from functools import wraps
from contextlib import closing from contextlib import closing
import sqlite3 import sqlite3
import MySQLdb as mdb import MySQLdb
from time import time, localtime, strftime from time import time, localtime, strftime
import locale import locale
import random import random
@ -70,7 +70,7 @@ def get_ip():
def get_player(player_id): def get_player(player_id):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select id,firstname,name,ban_end from players cur.execute("""select id,firstname,name,ban_end from players
where id=(?)""", [player_id]) where id=(?)""", [player_id])
@ -82,7 +82,7 @@ def get_player(player_id):
def get_player_from_ip(ip): def get_player_from_ip(ip):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select players.id,players.firstname,players.name, cur.execute("""select players.id,players.firstname,players.name,
machines.id,machines.ip,players.ban_end machines.id,machines.ip,players.ban_end
@ -103,7 +103,7 @@ def get_player_from_ip(ip):
def get_player_from_full_name(firstname, name): def get_player_from_full_name(firstname, name):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select players.id,players.firstname,players.name, cur.execute("""select players.id,players.firstname,players.name,
machines.id,machines.ip,players.ban_end machines.id,machines.ip,players.ban_end
@ -123,7 +123,7 @@ def get_player_from_full_name(firstname, name):
def is_banned(user_id): def is_banned(user_id):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select ban_end from players where id=(?)""", [user_id]) cur.execute("""select ban_end from players where id=(?)""", [user_id])
@ -150,7 +150,7 @@ def playable_required(f):
def get_players_not_banned(): def get_players_not_banned():
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select id,firstname,name from players cur.execute("""select id,firstname,name from players
where (?) > ban_end """, [time()]) where (?) > ban_end """, [time()])
@ -198,7 +198,7 @@ def ban(player_id, target_id, success):
banned_player = success and target or player banned_player = success and target or player
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select id,ban_end from players cur.execute("""select id,ban_end from players
where id=(?)""", [banned_player['id']]) where id=(?)""", [banned_player['id']])
@ -206,7 +206,7 @@ def ban(player_id, target_id, success):
con.commit() con.commit()
con.close() con.close()
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
ban_end = cur.fetchone()[0] ban_end = cur.fetchone()[0]
ban_end = time() + BAN_DURATION ban_end = time() + BAN_DURATION
@ -218,7 +218,7 @@ def ban(player_id, target_id, success):
con.commit() con.commit()
con.close() con.close()
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""insert into bans (player_id,target_id,success,time) cur.execute("""insert into bans (player_id,target_id,success,time)
values (?,?,?,?)""", [player['id'], target['id'], \ values (?,?,?,?)""", [player['id'], target['id'], \
success and 1 or 0, time()]) success and 1 or 0, time()])
@ -228,7 +228,7 @@ def ban(player_id, target_id, success):
def unban(player_id): def unban(player_id):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""update players set ban_end=(?) cur.execute("""update players set ban_end=(?)
where id=(?)""", [time() - BAN_DURATION, player_id]) where id=(?)""", [time() - BAN_DURATION, player_id])
@ -238,7 +238,7 @@ def unban(player_id):
def get_bans(player_id): def get_bans(player_id):
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
# Bannissements concernant le joueur : # Bannissements concernant le joueur :
cur.execute("""select player_id,target_id,success,time from bans cur.execute("""select player_id,target_id,success,time from bans
@ -273,7 +273,7 @@ def banned():
def statistiques(): def statistiques():
#Calcul des statistiques #Calcul des statistiques
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select firstname,name,ban_end from players""") cur.execute("""select firstname,name,ban_end from players""")
@ -308,7 +308,7 @@ def banned_ip():
abort(403) abort(403)
con = connect_sql() con = connect_sql()
cur = db.cursor() cur = con.cursor()
cur.execute("""select machines.ip from players cur.execute("""select machines.ip from players
inner join machines on players.id=machines.player_id inner join machines on players.id=machines.player_id