Skip to content

Instantly share code, notes, and snippets.

@altilunium
Created December 25, 2023 15:32
Show Gist options
  • Save altilunium/91daced2a1afe225a008af77481d3704 to your computer and use it in GitHub Desktop.
Save altilunium/91daced2a1afe225a008af77481d3704 to your computer and use it in GitHub Desktop.
access.log reader
import web
urls = (
'/', 'FileViewer'
)
class FileViewer:
def GET(self):
file_path = 'access.log'
try:
with open(file_path, 'r') as file:
file_content = file.read()
return render(file_content)
except FileNotFoundError:
return 'File not found.'
def render(content):
return f"""
<html>
<head>
<title>File Viewer</title>
</head>
<body>
<pre>{content}</pre>
</body>
</html>
"""
class MyApplication(web.application):
def run(self, port=8080, *middleware):
func = self.wsgifunc(*middleware)
return web.httpserver.runsimple(func, ('0.0.0.0', port))
if __name__ == "__main__":
app = MyApplication(urls, globals())
app.run(port=910)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment