Commit 69fae094 authored by fred's avatar fred
Browse files

add a command to import subscribers from spip

parent 973a83d8
# -*- coding: utf-8 -*-
from datetime import datetime
import time
import gzip
import xml.etree.ElementTree as ET
import os
import re
import urllib2
from PIL import Image
from optparse import make_option
from django.conf import settings
from django.core.files import File
from import BaseCommand, CommandError
from django.core.urlresolvers import reverse
from django.utils.html import strip_tags
from django.utils.text import slugify
from ...models import Subscriber
class Author(object):
id_auteur = None
email = None
class Command(BaseCommand):
args = 'filename'
help = 'Load newsletter subscribers from a Spip dump file'
def handle(self, filename, verbosity, **options):
self.verbose = (verbosity > 1)
with open(filename) as fd:
if self.verbose:
print 'Reading SPIP dump file'
content =
# the spip_courriers parts of the spip export are not properly
# encoded, we manually remove them here so the XML file can be
# parsed correctly.
content = content[:content.find('<spip_courriers>')] + \
self.root = ET.fromstring(content)
if self.verbose:
print 'Creating subscribers'
for author_xml in self.root.iter('spip_auteurs_elargis'):
if author_xml.find('spip_listes_format').text not in ('text', 'html'):
author = self.authors.get(author_xml.find('id_auteur').text)
if is None:
except Subscriber.DoesNotExist:
subscriber = Subscriber() =
subscriber.is_validated = True
subscriber.is_registered = True
subscriber.password = 'xxx'
def load_authors(self):
self.authors = {}
for author_xml in self.root.iter('spip_auteurs'):
author = Author()
for attr in ('id_auteur', 'email'):
setattr(author, attr, author_xml.find(attr).text)
self.authors[author.id_auteur] = author
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment