Created
December 25, 2023 15:32
-
-
Save altilunium/91daced2a1afe225a008af77481d3704 to your computer and use it in GitHub Desktop.
access.log reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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