Removed person list from table of contents.
[wolnelektury.git] / remove_duplicates.py
1 #!/usr/bin/env python
2 import sys
3
4 from django.core.management import setup_environ
5 from wolnelektury import settings
6 try:
7     set
8 except AttributeError:
9     from set import Set as set
10
11 setup_environ(settings)
12
13 from catalogue import models
14
15 fragment_identifiers = set()
16
17 print
18 print 'Before: %d fragments' % models.Fragment.objects.count()
19 print
20
21 for fragment in models.Fragment.objects.all():
22     if (fragment.book_id, fragment.anchor) in fragment_identifiers:
23         fragment.delete()
24         sys.stderr.write('X')
25     else:
26         fragment_identifiers.add((fragment.book_id, fragment.anchor))
27         sys.stderr.write('.')
28
29 print
30 print 'After: %d fragments' % models.Fragment.objects.count()
31 print