From 6d9a993d0adbaee68d3b68e90b024aa9f9ac3e5e Mon Sep 17 00:00:00 2001 From: guimoz Date: Mon, 30 Jan 2017 22:27:00 +0100 Subject: [PATCH] Ajout du script d'import --- import_bdd.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 import_bdd.py diff --git a/import_bdd.py b/import_bdd.py new file mode 100644 index 0000000..bb5702c --- /dev/null +++ b/import_bdd.py @@ -0,0 +1,22 @@ +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_sqlite = connect_sqlite() +cur_sqlite = con_sqlite.cursor() +# cur_sqlite.execute('''create table players (id,prenom,nom, etat)''') +# cur_sqlite.execute('''create table machines (id,uid_user,ip)''') +for user in User.objects.filter(school=1): + if user.has_access() and user.is_adherent(): + cur_sqlite.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): + cur_sqlite.execute("""insert into machines values (?,?,?) """,(i.id, user.uid_number, i.ipv4.ipv4)) +con_sqlite.commit() +con_sqlite.close()