diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-29 14:10:23 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-29 14:10:23 +0200 |
commit | 3dad3b6976ae9801caf6b0e2397e5efb5166d6d5 (patch) | |
tree | 8fa200512a9c244c1a04b1e5c3a21f5e01cee8f1 /scripts/2016-09-29-clean-dup-towns-pdl.py | |
parent | 34b4bd5dc5e07b8359bc7ed74c80f325cfed38e5 (diff) | |
download | Ishtar-3dad3b6976ae9801caf6b0e2397e5efb5166d6d5.tar.bz2 Ishtar-3dad3b6976ae9801caf6b0e2397e5efb5166d6d5.zip |
Maintenance script for de-dup towns
Diffstat (limited to 'scripts/2016-09-29-clean-dup-towns-pdl.py')
-rw-r--r-- | scripts/2016-09-29-clean-dup-towns-pdl.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/scripts/2016-09-29-clean-dup-towns-pdl.py b/scripts/2016-09-29-clean-dup-towns-pdl.py index e0fa1ffec..f454a7cac 100644 --- a/scripts/2016-09-29-clean-dup-towns-pdl.py +++ b/scripts/2016-09-29-clean-dup-towns-pdl.py @@ -2,16 +2,25 @@ from ishtar_common import Town dup_nb = 0 -for dpt in ('44', '49', '53', '72', '85'): - for town in Town.objects.filter(numero_insee__ilike=dpt): +pdl = [] +DPTS = ('44', '49', '53', '72', '85') + +for dpt in DPTS: + for town in Town.objects.filter(numero_insee__startswith=dpt): + pdl.append(town.pk) for dup in Town.objects.filter(name=town.name).exclude(pk=town.pk): + not_dup = False + for d in DPTS: + if dup.numero_insee.startswith(d): + not_dup = True + if not_dup: + continue for item in dup.file_main.all(): item.main_town = town - item.save() + p = item.save() for item in dup.parcels.all(): item.main_town = town - item.save() - + p = item.save() for item in dup.file.all(): item.towns.remove(dup) item.towns.add(town) @@ -19,5 +28,19 @@ for dpt in ('44', '49', '53', '72', '85'): item.towns.remove(dup) item.towns.add(town) dup_nb += 1 + dup.delete() + print("{} items cleaned".format(dup_nb)) + +strange = [] +for town in Town.objects.exclude(pk__in=pdl): + if (town.file_main.count() or town.parcels.count() or town.file.count() or + town.operations.count()): + strange.append(town) + continue + town.delete() + +print('* Problems with:') +for t in strange: + print(t) |