1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

fix json file format

test struct of json

json file finish
This commit is contained in:
Pierre-antoine Comby
2020-02-09 15:40:46 +01:00
parent 71a88e84f7
commit 4fe61fdc5f
2 changed files with 168 additions and 49 deletions

View File

@ -3,6 +3,7 @@
from django.core.management.base import BaseCommand
from django.utils import timezone
import psycopg2 as pg
import psycopg2.extras as pge
import json
@ -19,12 +20,19 @@ class Command(BaseCommand):
def handle(self, *args, **options):
map_file= options.get("map",None)
with open(map_file,'rb') as f:
with open(map_file,'r') as f:
map_dict = json.load(f);
#conn = pg.connect(database="nk15",user="nk_15")
#cur = conn.cursor()
conn = pg.connect(database="nk15",user="nk15_user")
cur = conn.cursor(cursor_factory = pge.DictCursor)
for old_table in map_dict:
print(old_table)
# Start with comptes table.
cur.execute("SELECT * FROM comptes ORDER BY -idbde LIMIT 5")
old_fields = [d[0] for d in cur.description]
print(type(old_fields))
for row in cur:
for old_field in old_fields:
print(old_field,row[old_field])