Accéder au contenu.
Menu Sympa

devel - [Devel] r109 - scripts

Objet : devel-adl

Archives de la liste

[Devel] r109 - scripts


Chronologique Discussions 
  • From: thomas AT lolut.utbm.info
  • To: devel AT agendadulibre.org
  • Subject: [Devel] r109 - scripts
  • Date: Sat, 15 Oct 2005 16:25:42 +0200 (CEST)
  • List-archive: <http://lolut.utbm.info/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>

Author: thomas
Date: 2005-10-15 16:25:41 +0200 (Sat, 15 Oct 2005)
New Revision: 109

Added:
scripts/adl-submit-old.py
scripts/adl-submit.py
scripts/event.xml
Log:
Ajout de scripts d'automatisation

Added: scripts/adl-submit-old.py
===================================================================
--- scripts/adl-submit-old.py 2005-10-15 14:24:04 UTC (rev 108)
+++ scripts/adl-submit-old.py 2005-10-15 14:25:41 UTC (rev 109)
@@ -0,0 +1,113 @@
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+
+# Copyright (C) 2005 Thomas Petazzoni <thomas.petazzoni AT enix.org>
+#
+# 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; version 2 of the License.
+#
+# 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
+
+#
+# This program allows to submit an event to the Agenda du Libre
+# website. It is very useful for regular events, that always have the
+# same description, hours, location, etc.
+#
+# Usage:
+# ./adl-submit.py YYYY-MM-DD
+#
+
+
+#
+# Configuration part
+#
+
+title = "Permanence Logiciels Libres"
+city = "Rennes"
+region = "6" # Bretagne
+
+start_hour = 18
+start_min = 0
+end_hour = 21
+end_min = 0
+
+description = """<p><a href=\"http://www.gulliver.eu.org\";>Gulliver</a>
organise chaque semaine une permanence <i>Logiciels Libres</i> ouverte �
tous, membres de l'association ou non.</p>
+
+<p>Durant cette permanence, vous pourrez trouver des r�ponses aux questions
que vous vous posez au sujet du Logiciel Libre, ainsi que de l'aide pour
r�soudre vos probl�mes d'installation, de configuration et d'utilisation de
Logiciels Libres. N'h�sitez pas � apporter votre ordinateur, afin que les
autres participants puissent vous aider.</p>
+
+<p>Une connexion Internet est disponible sur place, ainsi que les mises �
jour pour les distributions GNU/Linux les plus courantes.</p>
+
+<p>Cette permanence a lieu � la <a href=\"http://www.grand-cordel.com/\";>MJC
du Grand Cordel</a>, 18 rue des Plantes � Rennes.</p>"""
+
+url = "http://www.gulliver.eu.org";
+contact = "contact AT gulliver.eu.org"
+
+#
+# Code
+#
+
+def usage():
+ print "Usage: ./adl-submit.py YYYY-MM-DD"
+ sys.exit(1)
+
+import sys
+import pycurl
+import StringIO
+import re
+
+if len(sys.argv) != 2:
+ usage()
+
+regexp = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})')
+regexp_result = regexp.search(sys.argv[1])
+if regexp_result is None:
+ usage()
+
+year = regexp_result.groups(0)[0]
+month = regexp_result.groups(0)[1]
+day = regexp_result.groups(0)[2]
+
+if int(year) < 2005 or \
+ int(month) not in range (1, 13) or \
+ int(day) not in range (1, 32):
+ usage()
+
+curl = pycurl.Curl()
+contents = StringIO.StringIO()
+curl.setopt (curl.URL, "http://humanoidz.org/~thomas/agenda/submit.php";)
+# 'http://www.agendadulibre.org/submit.php')
+
+curl.setopt(curl.HTTPPOST, [('__event_title', title),
+ ('__event_start_day', day),
+ ('__event_start_month', month),
+ ('__event_start_year', year),
+ ('__event_start_hour', str(start_hour)),
+ ('__event_start_minute', str(start_min)),
+ ('__event_end_day', day),
+ ('__event_end_month', month),
+ ('__event_end_year', year),
+ ('__event_end_hour', str(end_hour)),
+ ('__event_end_minute', str(end_min)),
+ ('__event_description', str(description)),
+ ('__event_city', city),
+ ('__event_region', str(region)),
+ ('__event_locality', str(0)),
+ ('__event_url', url),
+ ('__event_contact', contact),
+ ('__event_save', str(1))])
+
+curl.setopt(curl.WRITEFUNCTION, contents.write)
+curl.perform()
+
+if curl.getinfo(curl.HTTP_CODE) != 200:
+ print "Error while submitting event"
+else:
+ print "Event succesfully submitted"


Property changes on: scripts/adl-submit-old.py
___________________________________________________________________
Name: svn:executable
+ *

Added: scripts/adl-submit.py
===================================================================
--- scripts/adl-submit.py 2005-10-15 14:24:04 UTC (rev 108)
+++ scripts/adl-submit.py 2005-10-15 14:25:41 UTC (rev 109)
@@ -0,0 +1,222 @@
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+
+# Copyright (C) 2005 Thomas Petazzoni <thomas.petazzoni AT enix.org>
+#
+# 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; version 2 of the License.
+#
+# 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 xml.dom.minidom
+import getopt
+import sys
+import pycurl
+import StringIO
+import re
+
+eventFields = [ "title", "start-date", "end-date", "start-hour",
+ "end-hour", "description", "city", "region",
+ "url", "contact" ]
+
+def Usage():
+ print """Soumettre un �v�nement dans l'Agenda du Libre
+
+Options:
+ --file event.xml Fichier XML d�crivant l'�v�nement.
+ --start-date YYYY-MM-DD Date de d�but de l'�v�nement.
+ --end-date YYYY-MM-DD Date de fin de l'�v�nement.
+ --start-hour HH:MM Heure de d�but de l'�v�nement.
+ --end-hour HH:MM Heure de fin de l'�v�nement.
+ --title chaine Titre de l'�v�nement.
+ --description chaine-html Description de l'�v�nement.
+ --city chaine Ville de l'�v�nement.
+ --region entier R�gion de l'�v�nement.
+ --url chaine URL d�crivant l'�v�nement.
+ --contact chaine E-mail de contact
+
+Exemple de fichier XML:
+ <?xml version="1.0" encoding="ISO-8859-1"?>
+ <event>
+ <title>Permanence Logiciels Libres</title>
+ <start-hour>18:00</start-hour>
+ <end-hour>21:00</end-hour>
+ <description><![CDATA[
+
+ <p><a href="http://www.gulliver.eu.org";>Gulliver</a> organise chaque
+ semaine une permanence <i>Logiciels Libres</i> ouverte � tous,
+ membre de l'association ou non.</p>
+
+ <p>Durant cette permanence, vous pourrez trouver des r�ponses aux
+ questions que vous vous posez au sujet du Logiciel Libre, ainsi que
+ de l'aide pour r�soudre vos probl�mes d'installation, de
+ configuration et d'utilisation de Logiciels Libres. N'h�sitez pas
+ � apporter votre ordinateur, afin que les autres participants
+ puissent vous aider.</p>
+
+ <p>Une connexion Internet est disponible sur place, ainsi que les
+ mises � jour pour les distributions GNU/Linux les plus
+ courantes.</p>
+
+ <p>Cette permanence a lieu � la <a
+ href=\"http://www.grand-cordel.com/\";>MJC du Grand Cordel</a>, 18
+ rue des Plantes � Rennes.</p>
+
+ ]]></description>
+ <city>Rennes</city>
+ <region>6</region>
+ <url>http://www.gulliver.eu.org</url>
+ <contact>contact AT gulliver.eu.org</contact>
+ </event>
+
+Valeurs des champs:
+ Le fichier XML peut contenir des champs dont le nom est semblable
+ � celui des options, � savoir start-date, end-date,
+ start-hour, end-hour, title, description, city, region, url et
+ contact. Si un champ est d�fini � la fois dans le fichier XML
+ et sur la ligne de commande, alors c'est la valeur donn�e sur la
+ ligne de commande qui l'emporte. Entre le fichier XML et la ligne de
+ commande, tous les champs doivent �tre d�finis, sinon l'ajout
+ de l'�v�nement sera refus�. Le seul champ qui peut �tre
+ vide est end-date, auquel cas il sera positionn� � la m�me
+ valeur que start-date.
+
+Exemple d'utilisation:
+ ./adl-submit.py --file event.xml --start-date 2005-12-10
+
+ Ajoutera l'�v�nement d�crit dans le fichier event.xml
+ (donn� ci-dessous) pour la date du 10 d�cembre 2005. Puisque
+ le champ end-date n'est pas sp�cifi�, alors il vaudra la
+ m�me chose que start-date, c'est � dire le 10 d�cembre
+ 2005.
+"""
+ sys.exit (1)
+
+def HandleXmlFile(file, values):
+ dom = xml.dom.minidom.parse(file)
+ for node in dom.getElementsByTagName("event")[0].childNodes:
+ if node.nodeType == node.ELEMENT_NODE:
+ val = node.childNodes[0]
+ for field in eventFields:
+ if node.nodeName == field:
+ values[field] = val.data.encode('iso-8859-1')
+
+def HandleParamValue(param, val, values):
+ for field in eventFields:
+ if param == "--" + field:
+ values[field] = val
+
+def ParseOptions(options):
+ getoptOptions = map (lambda elt: elt + "=", eventFields)
+ getoptOptions.append ("file=")
+ getoptOptions.append ("help")
+ eventFieldValues = {}
+
+ try:
+ opts, args = getopt.getopt(options, "", getoptOptions)
+ except getopt.GetoptError:
+ print "Unknown option"
+ Usage()
+
+ if opts == []:
+ Usage()
+
+ for param, val in opts:
+ if param == "--help":
+ Usage()
+
+ if param == "--file":
+ HandleXmlFile(val, eventFieldValues)
+ opts.remove ((param, val))
+
+ for param, val in opts:
+ HandleParamValue (param, val, eventFieldValues)
+
+ return eventFieldValues
+
+def SubmitEvent(event):
+
+ if event.has_key ("end-date") is False:
+ event ["end-date"] = event ["start-date"]
+
+ if re.compile(r'^[^\<\>]*$').search (event['title']) is None:
+ print "Formatting problem in title: '%s'" % event['title']
+ return
+
+ startDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['start-date'])
+ if startDate is None:
+ print "Formatting problem in starting date: '%s'. Must be
YYYY-MM-DD" % event['start-date']
+ return
+
+ endDate = re.compile(r'([0-9]{4})-0?(1?[0-9])-([0-9]{2})').search
(event['end-date'])
+ if endDate is None:
+ print "Formatting problem in ending date: '%s'. Must be YYYY-MM-DD"
% event['end-date']
+ return
+
+ startHour = re.compile(r'^([0-9]{2}):([0-9]{2})$').search
(event['start-hour'])
+ if startHour is None:
+ print "Formatting problem in starting hour: '%s'. Must be HH:MM" %
event['start-hour']
+ return
+
+ endHour = re.compile(r'^([0-9]{2}):([0-9]{2})$').search
(event['end-hour'])
+ if endHour is None:
+ print "Formatting problem in ending hour: '%s'. Must be HH:MM" %
event['end-hour']
+ return
+
+ if re.compile(r'^[^\<\>]*$').search (event['city']) is None:
+ print "Formatting problem in city: '%s'" % event['city']
+ return
+
+ if re.compile(r'^[0-9]*$').search (event['region']) is None:
+ print "Formatting problem in region: '%s'. Must be a number." %
event['region']
+ return
+
+ if re.compile(r'^http://.*$').search (event['url']) is None:
+ print "Formatting problem in url: '%s'. Must start with http://."; %
event['url']
+ return
+
+ if re.compile(r'^.*@.*$').search (event['contact']) is None:
+ print "Formatting problem in e-mail: '%s'. Must contain an '@'." %
event ['contact']
+ return
+
+ curl = pycurl.Curl()
+ contents = StringIO.StringIO()
+ curl.setopt (curl.URL, "http://humanoidz.org/~thomas/agenda/submit.php";)
+ # 'http://www.agendadulibre.org/submit.php')
+
+ curl.setopt(curl.HTTPPOST, [('__event_title',
str(event['title'])),
+ ('__event_start_day',
startDate.groups(0)[2]),
+ ('__event_start_month',
startDate.groups(0)[1]),
+ ('__event_start_year',
startDate.groups(0)[0]),
+ ('__event_start_hour',
str(startHour.groups(0)[0])),
+ ('__event_start_minute',
str(startHour.groups(0)[1])),
+ ('__event_end_day',
endDate.groups(0)[2]),
+ ('__event_end_month',
endDate.groups(0)[1]),
+ ('__event_end_year',
endDate.groups(0)[0]),
+ ('__event_end_hour',
str(endHour.groups(0)[0])),
+ ('__event_end_minute',
str(endHour.groups(0)[1])),
+ ('__event_description',
str(event['description'])),
+ ('__event_city',
str(event['city'])),
+ ('__event_region',
str(event['region'])),
+ ('__event_locality', str(0)),
+ ('__event_url', str(event['url'])),
+ ('__event_contact',
str(event['contact'])),
+ ('__event_save', str(1))])
+
+ curl.setopt(curl.WRITEFUNCTION, contents.write)
+ curl.perform()
+ if curl.getinfo(curl.HTTP_CODE) != 200:
+ print "Error while submitting event"
+ else:
+ print "Event succesfully submitted"
+
+event = ParseOptions(sys.argv[1:])
+SubmitEvent(event)


Property changes on: scripts/adl-submit.py
___________________________________________________________________
Name: svn:executable
+ *

Added: scripts/event.xml
===================================================================
--- scripts/event.xml 2005-10-15 14:24:04 UTC (rev 108)
+++ scripts/event.xml 2005-10-15 14:25:41 UTC (rev 109)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<event>
+ <title>Permanence Logiciels Libres</title>
+ <start-hour>18:00</start-hour>
+ <end-hour>21:00</end-hour>
+ <description><![CDATA[
+
+ <p><a href="http://www.gulliver.eu.org";>Gulliver</a> organise chaque
+ semaine une permanence <i>Logiciels Libres</i> ouverte � tous,
+ membre de l'association ou non.</p>
+
+ <p>Durant cette permanence, vous pourrez trouver des r�ponses aux
+ questions que vous vous posez au sujet du Logiciel Libre, ainsi que
+ de l'aide pour r�soudre vos probl�mes d'installation, de
+ configuration et d'utilisation de Logiciels Libres. N'h�sitez pas
+ � apporter votre ordinateur, afin que les autres participants
+ puissent vous aider.</p>
+
+ <p>Une connexion Internet est disponible sur place, ainsi que les
+ mises � jour pour les distributions GNU/Linux les plus
+ courantes.</p>
+
+ <p>Cette permanence a lieu � la <a
+ href=\"http://www.grand-cordel.com/\";>MJC du Grand Cordel</a>, 18
+ rue des Plantes � Rennes.</p>
+
+ ]]></description>
+ <city>Rennes</city>
+ <region>6</region>
+ <url>http://www.gulliver.eu.org</url>
+ <contact>contact AT gulliver.eu.org</contact>
+</event>





  • [Devel] r109 - scripts, thomas, 15/10/2005

Archives gérées par MHonArc 2.6.16.

Haut de le page