2 # -*- coding: utf-8 -*-
3 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 sys.path.append('./apps')
9 sys.path.append('./lib')
11 from django.core.management import setup_environ
12 from redakcja import settings
14 setup_environ(settings)
16 from catalogue.models import Book, Chunk
21 datepd = r"(<dc:date.pd[^>]+>)([0-9]+)(</dc:date.pd>)"
22 def fix(book, author, dry_run=True):
24 print "%s does not contain chunks" % book.slug
27 txt = fc.materialize()
30 m = re.search(datepd, txt)
32 print("%s: %s->%d" % (book.slug, m.groups()[1], int(m.groups()[1])+71))
34 print("%s: date.pd not found??" % (book.slug,))
38 tagopen, date, tagclose = match.groups()
40 date = str(int(date)+71)
42 dates['olddate'] = olddate
43 dates['overflow'] = False
45 dates['overflow'] = True
46 return tagopen+date+tagclose
48 new_txt = re.sub(datepd, up_date, txt)
50 print "%s: %s->%s" % (book.slug, dates['olddate'], dates['date'])
52 print "oops, new date would overfow to the future, i'm not changing"
54 # fc.commit(new_txt, author=author, description=u"Automatyczne poprawienie daty przejścia do domeny publicznej z %s na %s" % (dates['olddate'], dates['date']))
56 print "skipping %s" % book.slug
59 from django.contrib.auth.models import User
60 opts, oth_ = getopt.getopt(sys.argv[1:],[],[ "seriously"])
61 dry_run = not (("--seriously",'') in opts)
62 me = User.objects.get(username='marcinkoziej')
64 print "This is a dry run, to really change dates, run with --seriously"
65 for b in Book.objects.all():