* List of HTML files
* Improved search script
This commit is contained in:
parent
e32d8c8d64
commit
ff68c1111f
@ -18,6 +18,16 @@ second):
|
||||
<li><a href="registries/lsr-redundant.txt">List of redundants</a> (subtags redundant with other subtags)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>As HTML:
|
||||
<ul>
|
||||
<li><a href="registries/registry-html/language/">List of languages</a></li>
|
||||
<li><a href="registries/registry-html/script/">List of scripts</a></li>
|
||||
<li><a href="registries/registry-html/region/">List of regions</a> (including countries)</li>
|
||||
<li><a href="registries/registry-html/variant/">List of variants</a> (orthography, local dialects)</li>
|
||||
<li><a href="registries/registry-html/grandfathered/">List of grand-fathered</a> (tags which would otherwise be illegal but are maintained for compatibility, because they were previously used)</li>
|
||||
<li><a href="registries/registry-html/redundant/">List of redundants</a> (subtags redundant with other subtags)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>As <wikipedia>XML</wikipedia> :
|
||||
<ul>
|
||||
<li>According to <a href="registries/ltru.rnc">this schema</a>
|
||||
|
23
search.py
23
search.py
@ -13,11 +13,16 @@ import psycopg2
|
||||
from yattag import Doc
|
||||
|
||||
PORT = 4000
|
||||
#REDIRECTION_URL = "file:///home/stephane/src/Language-tags/GaBuZoMeu/registry-html" # Firefox does not accept a redirect to a file
|
||||
REDIRECTION_URL = "https://www.langtag.net/registries/registry-html"
|
||||
|
||||
def pack(start_response, status, data):
|
||||
def pack(start_response, status, data, headers = []):
|
||||
datae = data.encode() # Always encode to UTF-8
|
||||
response_headers = [("Content-type", "text/plain; charset=UTF-8"),
|
||||
response_headers = [("Content-type", "text/plain; charset=UTF-8"), # TODO allows the type HTML
|
||||
("Content-Length", str(len(datae)))]
|
||||
if headers != []:
|
||||
for header in headers:
|
||||
response_headers.append(header)
|
||||
start_response(status, response_headers)
|
||||
return [datae]
|
||||
|
||||
@ -33,6 +38,7 @@ def application(environ, start_response):
|
||||
body = environ["wsgi.input"].read(body_size)
|
||||
query = urllib.parse.parse_qsl(body.decode())
|
||||
form = {}
|
||||
headers = []
|
||||
for q in query:
|
||||
form[q[0]] = q[1]
|
||||
for mandatory in ["string", "what"]:
|
||||
@ -53,8 +59,11 @@ def application(environ, start_response):
|
||||
cursor.execute(sql, (term, ))
|
||||
mytuple = cursor.fetchone()
|
||||
status = "200 OK"
|
||||
if mytuple is not None:
|
||||
output = "TODO %s\r\n" % str(mytuple) # TODO display comments, preferredscript, addition date etc Or a redirect to mulhtml's result?
|
||||
if mytuple is not None:
|
||||
status = "308 Redirect"
|
||||
url = "%s/%s/%s.html" % (REDIRECTION_URL, form["what"], mytuple[1])
|
||||
headers.append(("Location", url))
|
||||
output = "Redirect to %s\r\n" % (url)
|
||||
else:
|
||||
if form["what"] == "language":
|
||||
sql = "SELECT * FROM Languages,Descriptions_Languages,Descriptions WHERE Descriptions_Languages.description = Descriptions.id AND Descriptions_Languages.lang = Languages.code AND position(%s in lower(Descriptions.description)) > 0;"
|
||||
@ -64,13 +73,11 @@ def application(environ, start_response):
|
||||
found = False
|
||||
output = ""
|
||||
for tuple in cursor.fetchall():
|
||||
output += "TODO %s\r\n" % str(tuple)
|
||||
output += "TODO %s\r\n" % str(tuple) # TODO make it a HTML list
|
||||
found = True
|
||||
if not found:
|
||||
output = "\"%s\" not found\r\n" % term
|
||||
# TODO HTML with a templating engine? Yattag, probably
|
||||
# TODO link to mulhtml results?
|
||||
return pack(start_response, status, output)
|
||||
return pack(start_response, status, output, headers)
|
||||
|
||||
if __name__ == "__main__":
|
||||
conn = psycopg2.connect("dbname=lsr")
|
||||
|
Loading…
Reference in New Issue
Block a user