import sqlite3 from users.models import User from machines.models import Machine,Interface SQLITE_FILENAME = '/var/www/re2o/players.db' def connect_sqlite(): return sqlite3.connect(SQLITE_FILENAME) # Connexion à la base SQLite locale con = connect_sqlite() cur = con.cursor() # cur.execute('''create table players (id,prenom,nom, etat)''') # cur.execute('''create table machines (id,uid_user,ip)''') cur.execute("""select id from players""") players = cur.fetchall() players = [player[0] for player in players] cur.execute("""select ip from machines""") machines = cur.fetchall() machines = [machine[0] for machine in machines] for user in User.objects.filter(school=1): if user.has_access() and (user.is_adherent() or user.end_adhesion()): if user.uid_number not in players: cur.execute("""insert into players values (?,?,?,?)""",(user.uid_number, user.name, user.surname, 0)) for m in Machine.objects.filter(user= user): for i in Interface.objects.filter(machine = m): if i.ipv4.ipv4 not in machines: cur.execute("""insert into machines values (?,?,?) """,(i.id, user.uid_number, i.ipv4.ipv4)) con.commit() con.close()