]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - search-tags.py
Python 3
[phdru.name/cgi-bin/blog-ru/search-tags.git] / search-tags.py
index c0919660befab6331cff2de6532e3b0b5c01b642..a844960b2f4601016de12085a5b0d4cc9c82790a 100755 (executable)
@@ -1,18 +1,21 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 # coding: koi8-r
 """Search tags CGI"""
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2014-2017 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2014-2024 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import cgi, sys
-from parsimonious import ParseError
+import cgi
+import sys
+
+from lark import ParseError
+
 from html.response import redirect, response
 from parser import parser
 
 form = cgi.FieldStorage()
-if not form.has_key('q'):
+if 'q' not in form:
     status = "400 Bad request"
     title = "Error!"
     body = "Required parameter is missing!"
@@ -20,23 +23,24 @@ if not form.has_key('q'):
 else:
     q = form['q'].value
     try:
-        tree = parser.compile(q)
+        tree = parser.parse(q)
     except ParseError:
         status = "400 Bad request"
         title = "Error!"
         body = "Bad query syntax!"
     else:
-        if tree[0] == 'NAME': # Single tag - just do redirect
+        if tree[0] == 'NAME':  # Single tag - just do redirect
             tag = tree[1]
             assert isinstance(tag, str)
             from tags import tag_exists
             if tag_exists(tag):
-                redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved")
+                redirect(
+                    "/Russian/blog/tags/%s.html" % tag, status="301 Moved")
                 sys.exit()
             status = "404 Tag not found"
             title = "Ошибка!"
             body = "Тег %s не существует!" % tag
-        else: # Process tree
+        else:  # Process tree
             from tags import find_tags
             posts = find_tags(tree)
             status = None
@@ -47,7 +51,10 @@ else:
     <ul>
     """]
                 for year, month, day, suburl, _title in posts:
-                    _posts.append('<li>%s-%s-%s <a href="../../../../Russian/blog/%s">%s</a></li>\n' % (year, month, day, suburl, _title))
+                    _posts.append(
+                        '<li>%s-%s-%s '
+                        '<a href="../../../../Russian/blog/%s">%s</a></li>\n'
+                        % (year, month, day, suburl, _title))
                 _posts .append("""\
     </ul>
     </p>