Accéder au contenu.
Menu Sympa

devel - [Devel] r447 - scripts

Objet : devel-adl

Archives de la liste

[Devel] r447 - scripts


Chronologique Discussions 
  • From: svn AT agendadulibre.org
  • To: devel AT agendadulibre.org
  • Subject: [Devel] r447 - scripts
  • Date: Fri, 7 Aug 2009 19:43:48 +0200 (CEST)
  • List-archive: <http://agendadulibre.org/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>

Author: thomas
Date: Fri Aug 7 19:43:45 2009
New Revision: 447

Log:
Nouveau script d'extraction des GULLs, depuis trouvetongull.info.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni AT free-electrons.com>

Added:
scripts/gulls2sql.py

Added: scripts/gulls2sql.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ scripts/gulls2sql.py Fri Aug 7 19:43:45 2009 (r447)
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009 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 3 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 urllib
+
+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,
+'71' : 5, '89' : 5, '22' : 6, '29' : 6, '35' : 6, '56' : 6, '18' : 7,
'28' : 7,
+'36' : 7, '37' : 7, '41' : 7, '45' : 7, '08' : 8, '10' : 8, '51' : 8,
'52' : 8,
+'2A' : 9, '2B' : 9, '25' : 10, '39' : 10, '70' : 10, '90' : 10, '27' : 11,
'76' : 11,
+'75' : 12, '77' : 12, '78' : 12, '91' : 12, '92' : 12, '93' : 12, '94' : 12,
'95' : 12,
+'11' : 13, '30' : 13, '34' : 13, '48' : 13, '66' : 13, '19' : 14, '23' : 14,
'87' : 14,
+'54' : 15, '55' : 15, '57' : 15, '88' : 15, '09' : 16, '12' : 16, '31' : 16,
'32' : 16,
+'46' : 16, '65' : 16, '81' : 16, '82' : 16, '59' : 17, '62' : 17, '44' : 18,
'49' : 18,
+'53' : 18, '72' : 18, '85' : 18, '02' : 19, '60' : 19, '80' : 19, '16' : 20,
'17' : 20,
+'79' : 20, '86' : 20, '04' : 21, '05' : 21, '06' : 21, '13' : 21, '83' : 21,
'84' : 21,
+'01' : 22, '07' : 22, '26' : 22, '38' : 22, '42' : 22, '69' : 22, '73' : 22,
'74' : 22,
+'971' : 23, '972' : 25, '973' : 24, '974' : 26, '98' : 28 }
+
+class GULL:
+ def __init__(self, name, department, region, city, url):
+ self.name = name
+ self.department = department
+ self.region = region
+ if city is None:
+ self.city = ""
+ else:
+ self.city = city
+ self.url = url
+
+ def genSQL(self):
+ print "insert into lugs (region, department, city, name, url) values
('%s', '%s', '%s', '%s', '%s');" \
+ % (str(self.region), self.department, self.city, self.name,
self.url)
+
+
+def getNodeText(node):
+ for n in node.childNodes:
+ if n.nodeType != n.TEXT_NODE:
+ continue
+ return n.nodeValue
+
+def handleGULL(node):
+ n = node.getElementsByTagName("pays")
+ country = getNodeText(n[0])
+ if country is not None:
+ return None
+ n = node.getElementsByTagName("nom")
+ name = getNodeText(n[0])
+ n = node.getElementsByTagName("departement")
+ department = getNodeText(n[0])
+ region = depts2region[department]
+ n = node.getElementsByTagName("url")
+ url = getNodeText(n[0])
+ n = node.getElementsByTagName("ville")
+ city = getNodeText(n[0])
+ return GULL(name, department, region, city, url)
+
+f = urllib.urlopen('http://www.trouvetongull.info/ftp/tableau.xml')
+dom = xml.dom.minidom.parse(f)
+gulls = []
+for node in dom.getElementsByTagName("informations"):
+ g = handleGULL(node)
+ if g is not None:
+ gulls.append(g)
+
+print "delete from lugs where id > 0;"
+for g in gulls:
+ g.genSQL()
+




  • [Devel] r447 - scripts, svn, 07/08/2009

Archives gérées par MHonArc 2.6.16.

Haut de le page