From 2de40e83f12774f6d91802aacf1b9a7bb9ead104 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 12 Feb 2020 00:12:31 +0100 Subject: [PATCH] [DEV] add script to generate the basic BDD for sqlite --- .../v0.0...v1.0/transfert_data.py | 74 ++++++++++ .../v0.0...v1.0/transfert_group.py | 89 ++++++++++++ .../v0.0...v1.0/transfert_saison.py | 94 +++++++++++++ .../v0.0...v1.0/transfert_type.py | 89 ++++++++++++ .../v0.0...v1.0/transfert_usivers.py | 89 ++++++++++++ .../v0.0...v1.0/transfert_video.py | 133 ++++++++++++++++++ 6 files changed, 568 insertions(+) create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_data.py create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_group.py create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_saison.py create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_type.py create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_usivers.py create mode 100755 back/transfer_bdd/v0.0...v1.0/transfert_video.py diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_data.py b/back/transfer_bdd/v0.0...v1.0/transfert_data.py new file mode 100755 index 0000000..5fa1ed4 --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_data.py @@ -0,0 +1,74 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_data.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_data.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data( + id INTEGER PRIMARY KEY , + sha512 TEXT NOT NULL, + mime_type TEXT NOT NULL, + size INTEGER NOT NULL, + create_date INTEGER NOT NULL, + original_name TEXT) +''') + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + time = elem["create_date"].replace("Z","").replace("H"," "); + tmp_time = parser.parse(time) + debug.info(" => " + str(tmp_time) + " from " + elem["create_date"]) + new_time = int(tmp_time.timestamp()) + mime_type = elem["mime_type"] + original_name = elem["original_name"] + sha512 = elem["sha512"] + size = elem["size"] + request_insert = (id, sha512, mime_type, size, new_time, original_name) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() + diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_group.py b/back/transfer_bdd/v0.0...v1.0/transfert_group.py new file mode 100755 index 0000000..b3b52c5 --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_group.py @@ -0,0 +1,89 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser +import datetime + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_group.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_group.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data ( + id INTEGER PRIMARY KEY , + create_date INTEGER NOT NULL, + modify_date INTEGER NOT NULL, + name TEXT NOT NULL, + description TEXT, + covers TEXT) +''') + +def list_to_string(data): + out = ""; + for elem in data: + if out != "": + out += "/" + out +=str(elem) + return out + +#sqlite3 bdd_group.db3 "SELECT * from data" + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + new_time = int(datetime.datetime.utcnow().timestamp()); + name = elem["name"] + if "description" not in elem.keys(): + description = None + else: + description = elem["description"] + if "covers" not in elem.keys(): + covers = [] + else: + covers = elem["covers"] + if covers == None: + covers = []; + request_insert = (id, new_time, new_time, name, description, list_to_string(covers)) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() + diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_saison.py b/back/transfer_bdd/v0.0...v1.0/transfert_saison.py new file mode 100755 index 0000000..0c6041e --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_saison.py @@ -0,0 +1,94 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser +import datetime + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_saison.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_saison.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data ( + id INTEGER PRIMARY KEY , + create_date INTEGER NOT NULL, + modify_date INTEGER NOT NULL, + number INTEGER NOT NULL, + description TEXT, + group_id INTEGER NOT NULL, + covers TEXT) +''') + +def list_to_string(data): + out = ""; + for elem in data: + if out != "": + out += "/" + out +=str(elem) + return out + +#sqlite3 bdd_group.db3 "SELECT * from data" + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + new_time = int(datetime.datetime.utcnow().timestamp()); + name = elem["number"] + if "group_id" not in elem.keys(): + group_id = None + else: + group_id = elem["group_id"] + if "description" not in elem.keys(): + description = None + else: + description = elem["description"] + if "covers" not in elem.keys(): + covers = [] + else: + covers = elem["covers"] + if covers == None: + covers = []; + request_insert = (id, new_time, new_time, name, description, group_id, list_to_string(covers)) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() + diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_type.py b/back/transfer_bdd/v0.0...v1.0/transfert_type.py new file mode 100755 index 0000000..191e992 --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_type.py @@ -0,0 +1,89 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser +import datetime + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_type.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_type.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data ( + id INTEGER PRIMARY KEY , + create_date INTEGER NOT NULL, + modify_date INTEGER NOT NULL, + name TEXT NOT NULL, + description TEXT, + covers TEXT) +''') + +def list_to_string(data): + out = ""; + for elem in data: + if out != "": + out += "/" + out +=str(elem) + return out + +#sqlite3 bdd_group.db3 "SELECT * from data" + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + new_time = int(datetime.datetime.utcnow().timestamp()); + name = elem["name"] + if "description" not in elem.keys(): + description = None + else: + description = elem["description"] + if "covers" not in elem.keys(): + covers = [] + else: + covers = elem["covers"] + if covers == None: + covers = []; + request_insert = (id, new_time, new_time, name, description, list_to_string(covers)) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() + diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_usivers.py b/back/transfer_bdd/v0.0...v1.0/transfert_usivers.py new file mode 100755 index 0000000..37b841b --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_usivers.py @@ -0,0 +1,89 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser +import datetime + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_univers.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_univers.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data ( + id INTEGER PRIMARY KEY , + create_date INTEGER NOT NULL, + modify_date INTEGER NOT NULL, + name TEXT NOT NULL, + description TEXT, + covers TEXT) +''') + +def list_to_string(data): + out = ""; + for elem in data: + if out != "": + out += "/" + out +=str(elem) + return out + +#sqlite3 bdd_group.db3 "SELECT * from data" + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + new_time = int(datetime.datetime.utcnow().timestamp()); + name = elem["name"] + if "description" not in elem.keys(): + description = None + else: + description = elem["description"] + if "covers" not in elem.keys(): + covers = [] + else: + covers = elem["covers"] + if covers == None: + covers = []; + request_insert = (id, new_time, new_time, name, description, list_to_string(covers)) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() + diff --git a/back/transfer_bdd/v0.0...v1.0/transfert_video.py b/back/transfer_bdd/v0.0...v1.0/transfert_video.py new file mode 100755 index 0000000..07db0d3 --- /dev/null +++ b/back/transfer_bdd/v0.0...v1.0/transfert_video.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## +#pip install paho-mqtt --user + +from realog import debug +import json +import os +import random +import copy +from dateutil import parser +import datetime + +def file_read_data(path): + if not os.path.isfile(path): + return "" + file = open(path, "r") + data_file = file.read() + file.close() + return data_file + +debug.info("Load old BDD: ") + +data = file_read_data('bdd_video.json') +my_old_bdd = json.loads(data) + +debug.info("open new BDD: ") +import sqlite3 +conn = sqlite3.connect('bdd_video.db3') + +debug.info("create the table:") + +c = conn.cursor() + +# Create table +c.execute(''' +CREATE TABLE data ( + id INTEGER PRIMARY KEY , + create_date INTEGER NOT NULL, + modify_date INTEGER NOT NULL, + name TEXT NOT NULL, + description TEXT, + covers TEXT, + data_id INTEGER, + type_id INTEGER, + univers_id INTEGER, + group_id INTEGER, + saison_id INTEGER, + date INTEGER, + episode INTEGER, + time INTEGER) +''') + +def list_to_string(data): + out = ""; + for elem in data: + if out != "": + out += "/" + out +=str(elem) + return out + +#sqlite3 bdd_group.db3 "SELECT * from data" + +debug.info("insert elements: ") +iii = 0; +for elem in my_old_bdd: + iii+=1; + debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element") + id = elem["id"] + time = elem["create_date"].replace("Z","").replace("H"," "); + tmp_time = parser.parse(time) + debug.info(" => " + str(tmp_time) + " from " + elem["create_date"]) + new_time = int(tmp_time.timestamp()) + modify_time = int(datetime.datetime.utcnow().timestamp()); + name = elem["name"] + if "description" not in elem.keys(): + description = None + else: + description = elem["description"] + if "covers" not in elem.keys(): + covers = [] + else: + covers = elem["covers"] + if covers == None: + covers = []; + if "data_id" not in elem.keys(): + data_id = None + else: + data_id = elem["data_id"] + if "type_id" not in elem.keys(): + type_id = None + else: + type_id = elem["type_id"] + if "univers_id" not in elem.keys(): + univers_id = None + else: + univers_id = elem["univers_id"] + if "group_id" not in elem.keys(): + group_id = None + else: + group_id = elem["group_id"] + if "saison_id" not in elem.keys(): + saison_id = None + else: + saison_id = elem["saison_id"] + if "date" not in elem.keys(): + date = None + else: + date = elem["date"] + if "episode" not in elem.keys(): + episode = None + else: + episode = elem["episode"] + if "time" not in elem.keys(): + time = None + else: + time = elem["time"] + request_insert = (id, new_time, modify_time, name, description, list_to_string(covers), data_id, type_id, univers_id, group_id, saison_id, date, episode, time) + c.execute('INSERT INTO data VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', request_insert) + +# Save (commit) the changes +conn.commit() + +# We can also close the connection if we are done with it. +# Just be sure any changes have been committed or they will be lost. +conn.close() +