Benoit Boissinot committed 8243fe8

add support for conseil constitutionnel

Comments (0)

Files changed (2)

 from google.appengine.ext import db, webapp
 from google.appengine.ext.webapp.util import run_wsgi_app
 from django.utils import simplejson as json
-import re, urllib
+import re, urllib, logging, urllib2
 def quoteurnre(urlre):
     return urllib.quote(urlre, safe='/^$()[]?+.*{}\\')
+class CCID(db.Model):
+    num = db.StringProperty(required=True)
+    htmlid = db.StringProperty(required=True)
 def resolvesenat(query):
     typemapping = {
             'proposition.loi': 'ppl',
         return None
     return "" % (legi, type, id)
+def resolvecc(query):
+    m ='urn:lex:fr:conseil.constitutionnel:decision:(\d{4})(-\d{2}-\d{2})?;(\d+[^;:]*?)$', query)
+    if not m:
+        return None
+    year = int(, 10)
+    if year < 2000:
+        ccid = '%02d-%s' % (year % 100,
+    else:
+        ccid = '%d-%s' % (year,
+    ccid = ccid.lower()
+    id = CCID.all().filter('num = ', ccid).get()
+    if id is None:
+        key = re.match(r'\d+-\d+', ccid).group(0)
+        try:
+            url = '' % key
+  'fetching... %s' % url)
+            search = urllib2.urlopen(url).read()
+            htmlid ='<span class="resultatRechercheTitre"><a href=".*?\.(\d+)\.html">', search).group(1)
+            id = CCID(num=ccid, htmlid=htmlid)
+            id.put()
+        except:
+            raise
+            return None
+    return "" % id.htmlid
 resolve = {
         'senat': resolvesenat,
         'assemblee.nationale': resolvean,
+        'conseil.constitutionnel': resolvecc,
 class Resolver(webapp.RequestHandler):


-		<p>A very simple <a href="">urn:lex</a> resolver for France. It currently supports only some links to and</p>
-		<p>Some examples: <a href="/redirect?urn:lex:fr:assemblee.nationale:projet.loi:13.legislature;2339">urn:lex:fr:assemblee.nationale:projet.loi:13.legislature;2339</a> or <a href="/redirect?urn:lex:fr:senat:proposition.loi:2008;16">urn:lex:fr:senat:proposition.loi:2008;16</a>.</p>
+		<p>A very simple <a href="">urn:lex</a> resolver for France. It currently supports only some links to, and</p>
+		<p>Some examples: <a href="/redirect?urn:lex:fr:assemblee.nationale:projet.loi:13.legislature;2339">urn:lex:fr:assemblee.nationale:projet.loi:13.legislature;2339</a>, <a href="/redirect?urn:lex:fr:senat:proposition.loi:2008;16">urn:lex:fr:senat:proposition.loi:2008;16</a>, or <a href="/redirect?urn:lex:fr:conseil.constitutionnel:decision:2009-06-10;580dc">urn:lex:fr:conseil.constitutionnel:decision:2009-06-10;580dc</a>.</p>
 		<p>Comments, suggestions: <a href=""></a>, code on <a href="">bitbucket</a>.</p>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.