X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b3a2a942879cf81025be9cbfcb924b3ffca038c0..1e5176481313c3129d2f353993dbb721b21ef232:/scripts/import_links.py?ds=inline diff --git a/scripts/import_links.py b/scripts/import_links.py new file mode 100644 index 000000000..ea4380fb8 --- /dev/null +++ b/scripts/import_links.py @@ -0,0 +1,36 @@ +import sys +sys.path.insert(0, '../apps') +sys.path.insert(0, '../lib') +sys.path.insert(0, '../wolnelektury') +sys.path.insert(0, '..') + +from django.core.management import setup_environ +from wolnelektury import settings +import sys + +setup_environ(settings) + +from catalogue.models import Book, Tag + + +def import_tags(file_name, attribute): + for line in file(file_name): + slug, link = line.split() + link = link.strip('\n') + try: + book = Book.objects.get(slug=slug) + setattr(book, attribute, link) + book.save() + print 'Link %s for book %s added!' % (link, book) + except Book.DoesNotExist: + try: + tag = Tag.objects.get(slug=slug) + setattr(tag, attribute, link) + tag.save() + print 'Link %s for tag %s added!' % (link, tag) + except Tag.DoesNotExist: + print 'Invalid slug %s!' % slug + + +import_tags('gazeta-links', 'gazeta_link') +