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.
7 sys.path.insert(0, '../apps')
8 sys.path.insert(0, '../lib')
9 sys.path.insert(0, '../wolnelektury')
10 sys.path.insert(0, '..')
12 from django.core.management import setup_environ
13 from wolnelektury import settings
16 setup_environ(settings)
18 from catalogue.models import Book, Tag
21 def import_links(file_name, attribute):
22 for line in file(file_name):
23 slug, link = line.split()
24 link = link.strip('\n')
26 book = Book.objects.get(slug=slug)
27 setattr(book, attribute, link)
29 print 'Link %s for book %s added!' % (link, book)
30 except Book.DoesNotExist:
32 tag = Tag.objects.get(slug=slug)
33 setattr(tag, attribute, link)
35 print 'Link %s for tag %s added!' % (link, tag)
36 except Tag.DoesNotExist:
37 print 'Invalid slug %s!' % slug
40 import_links('gazeta-links', 'gazeta_link')
41 import_links('wiki-links', 'wiki_link')