From 4c93aaa7c94e4475ac6efbfeefbd747f1467b6ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Mon, 22 Sep 2008 17:39:28 +0200 Subject: [PATCH] Added script to remove duplicated fragments. --- remove_duplicates.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 remove_duplicates.py diff --git a/remove_duplicates.py b/remove_duplicates.py new file mode 100755 index 000000000..e72512ba4 --- /dev/null +++ b/remove_duplicates.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import sys + +from django.core.management import setup_environ +from wolnelektury import settings +try: + set +except AttributeError: + from set import Set as set + +setup_environ(settings) + +from catalogue import models + +fragment_identifiers = set() + +print +print 'Before: %d fragments' % models.Fragment.objects.count() +print + +for fragment in models.Fragment.objects.all(): + if (fragment.book_id, fragment.anchor) in fragment_identifiers: + fragment.delete() + sys.stderr.write('X') + else: + fragment_identifiers.add((fragment.book_id, fragment.anchor)) + sys.stderr.write('.') + +print +print 'After: %d fragments' % models.Fragment.objects.count() +print \ No newline at end of file -- 2.20.1