Personal tools
Importazione di eventi
Importazione di news da news.ictp.it a plone
Ok, questa e' molto tricky, a qualcuno non piacera' di certo :).
Innanzitutto ho importato le news. Ci sara' sicuramente un modo intelligente, ma io me le sono scaricate con un semplice:
for i in `seq 1 400`; do echo http://news.ictp.it/index.php?p=$i; done | xargs wget
Per convenienza ho rinominato i file:
rename 's/.*p=(.*)/news_$1.html/g' index.php\?p\=*
A questo punto ho eliminato i file corrispondenti a news inesistenti:
grep 'Sorry, no newsfeeds matched your criteria.' * -l|xargs rm
Ora avevo le news che mi interessavano. Dando un'occhiata al sorgente, estrapolo una regular expression che mi permette di prendere i dati che mi servono. A questo punto il mio script python diventa:
#!/usr/bin/python
# @(#)extract.py
#
#
# Copyright (C) 2007 by Antonio Messina <antonio.messina@ictp.it> for the
# Abdus Salam International Center for Theoretical Physics (ICTP).
#
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import re
import sys
regex=re.compile('<!-- Beginning of maincontent -->.*<h2>(.*)</h2>.*<h3 .*<a[^>]*>([^<]*)</a>.*</h3>.*<ul class="post-categories">[^<]*<li><a href.*cat=([0-9]*)[^>]*>([^<]*).*<div class="storycontent">(.*)</div>.*</div>.*</div>.*</div><!-- End of maincontent -->', flags=re.MULTILINE|re.DOTALL)
file=sys.argv[1]
f=open(file,'r')
doc=f.read()
f.close()
res=regex.search(doc)
date_l = res.group(1).split('/')
date="%4d/%02d/%02d" % (int(date_l[2]),int(date_l[1]),int(date_l[0]))
title = res.group(2)
cat_n = int(res.group(3))
cat = res.group(4)
text = res.group(5).strip()
print "title: "+title
print "startDate: %s 08:00:00.000 GMT+2" % date
print "eventType: news_%s" % cat
print "excludeFromNav: True"
print "Content-Type: text/html\n\n" + text
In pratica viene estrapolata la data, il titolo ed il testo. Un altro ciclo for in shell ci permette di creare i file:
for i in news_*.html; do ./extract.py $i > $i.event || echo $i; done
Dovrebbe stampare solo errori e i nomi dei file con errori. Nel mio caso e' andato tutto liscio (si', sono sorpreso pure io!)
Infine il passo finale: copiare (via webdav usando emacs, o via ftp) i vari file .event dove si vuole. Verranno automaticamente creati oggetti di tipo event in plone.
Note:
E' possibile specificare altri campi. A titolo informativo, una delle news contiene
id: news_100.html.event title: 31 July Deadline for Templeton Prizes excludeFromNav: False subject: description: contributors: creators: zadmin effectiveDate: 2007/09/26 19:05:44.602 GMT+2 expirationDate: None language: rights: creation_date: 2007/09/26 19:03:11.504 GMT+2 modification_date: 2007/09/26 19:05:44.603 GMT+2 startDate: 2005/07/14 08:00:00 GMT+2 endDate: 2007/09/26 19:03:11.504 GMT+2 location: attendees: eventType: eventUrl: contactName: contactEmail: contactPhone: relatedItems: allowDiscussion: None