2 sys.path.insert(0, '../apps')
3 sys.path.insert(0, '../lib')
4 sys.path.insert(0, '../wolnelektury')
5 sys.path.insert(0, '..')
7 from django.core.management import setup_environ
8 from wolnelektury import settings
11 setup_environ(settings)
13 from catalogue.models import Book, Tag
16 def import_links(file_name, attribute):
17 for line in file(file_name):
18 slug, link = line.split()
19 link = link.strip('\n')
21 book = Book.objects.get(slug=slug)
22 setattr(book, attribute, link)
24 print 'Link %s for book %s added!' % (link, book)
25 except Book.DoesNotExist:
27 tag = Tag.objects.get(slug=slug)
28 setattr(tag, attribute, link)
30 print 'Link %s for tag %s added!' % (link, tag)
31 except Tag.DoesNotExist:
32 print 'Invalid slug %s!' % slug
35 import_links('gazeta-links', 'gazeta_link')
36 import_links('wiki-links', 'wiki_link')