Commits

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 "http://www.assemblee-nationale.fr/%02d/%s%04d.asp" % (legi, type, id)
 
+def resolvecc(query):
+    m = re.search(r'urn:lex:fr:conseil.constitutionnel:decision:(\d{4})(-\d{2}-\d{2})?;(\d+[^;:]*?)$', query)
+    if not m:
+        return None
+    year = int(m.group(1), 10)
+    if year < 2000:
+        ccid = '%02d-%s' % (year % 100, m.group(3))
+    else:
+        ccid = '%d-%s' % (year, m.group(3))
+    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 = 'http://recherche.conseil-constitutionnel.fr/?expert=2&filtres3=%s' % key
+            logging.info('fetching... %s' % url)
+            search = urllib2.urlopen(url).read()
+            htmlid = re.search(r'<span class="resultatRechercheTitre"><a href=".*?\.(\d+)\.html">', search).group(1)
+            id = CCID(num=ccid, htmlid=htmlid)
+            id.put()
+        except:
+            raise
+            return None
+    return "http://www.conseil-constitutionnel.fr/decision.%s.html" % id.htmlid
+
 resolve = {
         'senat': resolvesenat,
         'assemblee.nationale': resolvean,
+        'conseil.constitutionnel': resolvecc,
 }
 
 class Resolver(webapp.RequestHandler):

static/index.html

 <html>
 	<body>
-		<p>A very simple <a href="http://tools.ietf.org/html/draft-spinosa-urn-lex-01">urn:lex</a> resolver for France. It currently supports only some links to senat.fr and assemblee-nationale.fr.</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="http://tools.ietf.org/html/draft-spinosa-urn-lex-01">urn:lex</a> resolver for France. It currently supports only some links to senat.fr, assemblee-nationale.fr and conseil-constitutionnel.fr.</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="mailto:bboissin@gmail.com">bboissin@gmail.com</a>, code on <a href="http://bitbucket.org/bboissin/urnlex/">bitbucket</a>.</p>
 	</body>
 </html>
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 ProjectModifiedEvent.java.
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.