Created
December 18, 2015 06:30
-
-
Save a10y/d8c646dddc157617f23b to your computer and use it in GitHub Desktop.
Simple python3 web server to view your mining status
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
#!/usr/bin/env python3 | |
# Written by Andrew Duffy, December 2015 | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
from subprocess import Popen, PIPE | |
SCRIPT_TEXT = b""" | |
<script type="text/javascript"> | |
setTimeout(function() { location.reload() }, 5000) | |
</script> | |
""" | |
class MiningStatusHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
proc = Popen(['21', 'status'], stdout=PIPE) | |
proc.wait() | |
text = proc.stdout.read().replace(b'\n', b'<br>') | |
self.wfile.write(b'<html>') | |
self.wfile.write(b'<body>') | |
self.wfile.write(b'<p>') | |
self.wfile.write(text) | |
self.wfile.write(b'</p>') | |
self.wfile.write(SCRIPT_TEXT) | |
self.wfile.write(b'</body>') | |
self.wfile.write(b'</html>') | |
return | |
print('serving on port 8080...') | |
SERVER = ('', 8080) | |
server = HTTPServer(SERVER, MiningStatusHandler) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment