URI: 
       index.cgi - mediawiki-gopher - mediawiki gopher frontend
  HTML git clone git://bitreich.org/mediawiki-gopher git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/mediawiki-gopher
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
       index.cgi (1543B)
       ---
            1 #!/usr/bin/env python
            2 # coding=utf-8
            3 #
            4 # © 2025-2026 Christoph Lohmann <20h@r-36.net>
            5 #
            6 # This file is published under the terms of the GPLv3.
            7 #
            8 
            9 import os
           10 import sys
           11 import getopt
           12 import requests
           13 import html2text
           14 
           15 def main(args):
           16         if len(args) != 7:
           17                 sys.stderr.write("Must be run as geomyidae dcgi.\n")
           18                 return 1
           19         g_search = args[1]
           20         g_arguments = args[2]
           21         g_host = args[3]
           22         g_port = args[4]
           23         g_traversal = args[5]
           24         g_base = g_selector = args[6]
           25         if len(g_traversal) > 0:
           26                 g_base = g_selector[:-len(g_traversal)]
           27         g_usetls = os.getenv("GOPHERS", "off")
           28         if g_usetls == "on":
           29                 g_uri = "gophers://"
           30         else:
           31                 g_uri = "gopher://"
           32         g_uri += g_host
           33         if g_port != "70":
           34                 g_uri += ":" + g_port
           35         g_uri += g_base
           36 
           37         mw_base = os.getenv("MEDIAWIKI_BASE", "https://en.wikipedia.org")
           38         mw_rest_api = os.getenv("MEDIAWIKI_REST", "https://en.wikipedia.org/w/rest.php")
           39         mw_page = "%s/v1/page" % (mw_rest_api)
           40 
           41         # Mandatory for wikipedia.
           42         headers = { "User-Agent": "gopher mediawiki frontend/0.1" }
           43 
           44         cmds = g_traversal.split("/")
           45         if len(cmds) == 0:
           46                 gph = "3Not found.\t\t\n"
           47         elif len(cmds) == 1:
           48                 gph = "3Not found.\t\t\n"
           49         elif cmds[1] == "":
           50                 gph = "3Not found.\t\t\n"
           51         else:
           52                 page = cmds[1]
           53                 if page.endswith(".txt"):
           54                         page = page[:-4]
           55                 html = requests.get("%s/%s/html" % (mw_page, \
           56                                 page), headers=headers)
           57                 h2t = html2text.HTML2Text()
           58                 h2t.ignore_links = True
           59                 h2t.ignore_images = True
           60                 gph = h2t.handle(html.text)
           61 
           62         sys.stdout.write(gph)
           63         sys.stdout.flush()
           64         
           65         return 0
           66 
           67 if __name__ == "__main__":
           68         sys.exit(main(sys.argv))
           69