Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
django-panik-newsletter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
django-panik-newsletter
Commits
69fae094
Commit
69fae094
authored
Nov 03, 2013
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a command to import subscribers from spip
parent
973a83d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
newsletter/management/commands/load-from-spip-liste.py
newsletter/management/commands/load-from-spip-liste.py
+78
-0
No files found.
newsletter/management/commands/load-from-spip-liste.py
0 → 100644
View file @
69fae094
# -*- 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
django.core.management.base
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
=
fd
.
read
()
# 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>'
)]
+
\
content
[
content
.
rfind
(
'</spip_courriers>'
)
+
17
:]
self
.
root
=
ET
.
fromstring
(
content
)
self
.
load_authors
()
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'
):
continue
author
=
self
.
authors
.
get
(
author_xml
.
find
(
'id_auteur'
).
text
)
if
author
.
email
is
None
:
continue
try
:
Subscriber
.
objects
.
get
(
email
=
author
.
email
)
except
Subscriber
.
DoesNotExist
:
pass
else
:
continue
subscriber
=
Subscriber
()
subscriber
.
email
=
author
.
email
subscriber
.
is_validated
=
True
subscriber
.
is_registered
=
True
subscriber
.
password
=
'xxx'
subscriber
.
save
()
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment