[Devel] r155 - scripts

svn at agendadulibre.org svn at agendadulibre.org
Dim 5 Fév 20:09:41 CET 2006


Author: thomas
Date: Sun Feb  5 20:09:40 2006
New Revision: 155

Modified:
   scripts/extract-gulls.py
Log:

 - Ajout d'une licence.
 - Explication de l'utilité du script.
 - Reformatage de lignes trop longues
 - Suppression de hack qui ont été intégrés directement
   dans la liste de l'AFUL.



Modified: scripts/extract-gulls.py
==============================================================================
--- scripts/extract-gulls.py	(original)
+++ scripts/extract-gulls.py	Sun Feb  5 20:09:40 2006
@@ -1,9 +1,35 @@
 #!/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 script is used for the french Agenda du Libre, hosted at
+# http://www.agendadulibre.org. It allows to convert the list of Linux
+# User Groups provided by the AFUL at http://www.aful.org/gul/liste
+# into a SQL requests list. In this form, the list of LUGs is usable
+# inside the Agenda du Libre.
+#
+# Yes, this script is hacky.
+
 import HTMLParser, urllib, urlparse
 import re
 
+# The list of LUGs provided by AFUL is sorted by departements, but the
+# Agenda du Libre works with region. This array allows to convert a
+# departement to its corresponding region.
 depts2region = {
 '67' : 1,  '68' : 1,  '24' : 2,  '33' : 2,  '40' : 2,  '47' : 2,  '64' : 2,  '03' : 3,
 '15' : 3,  '43' : 3,  '63' : 3,  '14' : 4,  '50' : 4,  '61' : 4,  '21' : 5,  '58' : 5,
@@ -20,6 +46,7 @@
 '971' : 23, '972' : 25, '973' : 24, '974' : 26 }
 
 class GULLParser(HTMLParser.HTMLParser):
+
     def __init__(self):
         HTMLParser.HTMLParser.__init__(self)
         self.seen = {}
@@ -31,7 +58,10 @@
         self.inCountry = False
         self.currentCountry = None
 
+    # Called for each starting HTML tag.
     def handle_starttag(self, tag, attributs):
+
+        # <h3> fields delimit the countries
         if tag == 'h3':
             self.inCountry = True
             return
@@ -39,22 +69,26 @@
         if self.currentCountry != "France":
             return
 
+        # <h4> fields delimit the departements
         if tag == 'h4':
             for nom, valeur in attributs:
                 if nom == 'id':
                     departement = re.compile(r'^fr\-([0-9]*)$').search (valeur)
                     if departement is not None:
                         self.currentDepartement = departement.group(1)
+
+        # There is one <li> tag for each LUG
         if tag == 'li' and self.currentDepartement != 0:
             self.inLug = True
+
+        # Extract the URL of the LUG.
         if self.inLug and tag == 'a':
             self.inLugLink = True
             for nom, valeur in attributs:
                 if nom == 'href' and self.currentLugLink is None:
-                    valeur = valeur.replace("http://g3l.org", "http://www.g3l.org")
-                    valeur = valeur.replace("mailto:gmull à laposte.net", "http://gmull.tuxfamily.org/")
                     self.currentLugLink = valeur
 
+    # Called for each ending HTML tag.
     def handle_endtag(self, tag):
         if tag == 'h3':
             self.inCountry = False
@@ -65,8 +99,13 @@
 
         if tag == 'li' and self.currentDepartement != 0:
             self.inLug = False
-            if depts2region.has_key(self.currentDepartement) and self.currentLugName is not None and self.currentLugLink is not None:
-                print "insert into lugs (region, department, name, url) values ('" + str(depts2region[str(self.currentDepartement)]) + "', '" + self.currentDepartement + "', '" + self.currentLugName + "', '" + self.currentLugLink + "');"
+            # We have all informations about this LUG, print an SQL request.
+            if (depts2region.has_key(self.currentDepartement)
+                and self.currentLugName is not None
+                and self.currentLugLink is not None):
+                print "insert into lugs (region, department, name, url) values ('%s', '%s', '%s', '%s')" \
+                      % (str(depts2region[str(self.currentDepartement)]), self.currentDepartement,
+                         self.currentLugName, self.currentLugLink)
             self.currentLugLink = None
             self.currentLugName = None
 
@@ -74,6 +113,7 @@
             self.inLugLink = False
 
     def handle_data(self, data):
+        # Store the current country name
         if self.inCountry:
             self.currentCountry = data
 


Plus d'informations sur la liste de diffusion Devel