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])+70))
34 print("%s: date.pd not found??" % (book.slug,))
38 tagopen, date, tagclose = match.groups()
40 date = str(int(date)+70)
42 dates['olddate'] = olddate
43 return tagopen+date+tagclose
44 new_txt = re.sub(datepd, up_date, txt)
45 print "%s: %s->%s" % (book.slug, dates['olddate'], dates['date'])
46 fc.commit(new_txt, author=author, description=u"Automatyczne poprawienie daty przejścia do domeny publicznej z %s na %s" % (dates['olddate'], dates['date']))
50 from django.contrib.auth.models import User
51 opts, oth_ = getopt.getopt(sys.argv[1:],[],[ "seriously"])
52 dry_run = not (("--seriously",'') in opts)
53 me = User.objects.get(username='marcinkoziej')
55 print "This is a dry run, to really change dates, run with --seriously"
56 for b in Book.objects.all():