2017-01-31 13:17:50 +00:00
|
|
|
import MySQLdb
|
2017-01-31 11:06:02 +00:00
|
|
|
from users.models import User
|
2017-01-30 21:27:00 +00:00
|
|
|
from machines.models import Machine,Interface
|
|
|
|
|
2017-01-31 13:17:50 +00:00
|
|
|
def connect_sql():
|
|
|
|
return MySQLdb.connect(host="roulette.rez", # your host, usually localhost
|
|
|
|
user="hydra-user", # your username
|
|
|
|
passwd="q5kBLchS6ooAZDSxMeJG2gdf4gmJcfS5", # your password
|
|
|
|
db="roulette") # name of the data base
|
2017-01-30 21:27:00 +00:00
|
|
|
|
2018-01-12 23:30:16 +00:00
|
|
|
def process():
|
|
|
|
# Connexion à la base SQLite locale
|
|
|
|
con = connect_sql()
|
|
|
|
cur = con.cursor()
|
|
|
|
print("Drop tables")
|
|
|
|
cur.execute('''drop table if exists players''')
|
|
|
|
cur.execute('''drop table if exists machines''')
|
|
|
|
print("create tables")
|
|
|
|
cur.execute('''create table players (id int,firstname text,name text, ban_end float)''')
|
|
|
|
cur.execute('''create table machines (id int,player_id int,ip text)''')
|
|
|
|
print("select players")
|
|
|
|
cur.execute("""select id from players""")
|
|
|
|
players = cur.fetchall()
|
|
|
|
players = [player[0] for player in players]
|
|
|
|
|
|
|
|
print("select machines")
|
|
|
|
cur.execute("""select ip from machines""")
|
|
|
|
machines = cur.fetchall()
|
|
|
|
machines = [machine[0] for machine in machines]
|
|
|
|
u = User.objects.filter(school=1)
|
|
|
|
print("Let's go !!!")
|
|
|
|
for x,user in enumerate(u):
|
|
|
|
print("Avancement : {}%".format(round(x/len(u)*100, 2)), end="\r")
|
|
|
|
if user.has_access() and (user.is_adherent() or user.end_adhesion()):
|
|
|
|
if user.uid_number not in players:
|
|
|
|
s = """insert into players values ({},"{}","{}",{});""".format(user.uid_number, user.name, user.surname, 0)
|
|
|
|
cur.execute(s)
|
|
|
|
for m in Machine.objects.filter(user= user):
|
|
|
|
for i in Interface.objects.filter(machine = m):
|
|
|
|
if i.ipv4.ipv4 not in machines:
|
|
|
|
s = """insert into machines values ({},{},"{}") ;""".format(i.id, user.uid_number, i.ipv4.ipv4)
|
|
|
|
cur.execute(s)
|
|
|
|
con.commit()
|
|
|
|
con.close()
|