Commits

Benoit Boissinot committed f89ba27

urnlex first version

  • Participants

Comments (0)

Files changed (3)

+application: urnlex
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /urn:lex:fr:.*
+  script: main.py
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run.  If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED").  If you want to manage some indexes
+# manually, move them above the marker line.  The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
+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 urllib
+
+def quoteurnre(urlre):
+    return urllib.quote(urlre, safe='/()[]?+.*{}\\')
+
+class Senat(webapp.RequestHandler):
+    typemapping = {
+            'proposition.loi': 'ppl',
+            'projet.loi': 'pjl',
+            'proposition.resolution': 'ppr'
+    }
+    def get(self, type, year, id):
+        year = int(year, 10) % 100
+        id = int(id, 10)
+        try:
+            type = self.typemapping[type]
+        except KeyError:
+            self.error(404)
+        self.redirect("http://www.senat.fr/leg/%s%02d-%03d.html" % (type, year, id))
+
+class AssembleeNationale(webapp.RequestHandler):
+    typemapping = {
+            'proposition.loi': 'propositions/pion',
+            'projet.loi': 'projets/pl',
+    }
+    def get(self, type, legi, id):
+        legi = int(legi, 10)
+        id = int(id, 10)
+        try:
+            type = self.typemapping[type]
+        except KeyError:
+            self.error(404)
+        self.redirect("http://www.assemblee-nationale.fr/%02d/%s%04d.asp" % (legi, type, id))
+
+application = webapp.WSGIApplication(
+    [(quoteurnre(r'/urn:lex:fr:senat:(.*?):(\d{4});(\d+)'), Senat),
+     (quoteurnre(r'/urn:lex:fr:assemblee.nationale:(.*?):(\d+).legislature;(\d+)'), AssembleeNationale),
+    ], debug=True)
+
+def main():
+    run_wsgi_app(application)
+
+if __name__ == "__main__":
+    main()