Skip to content

Instantly share code, notes, and snippets.

@a10y
Created December 18, 2015 06:30
Show Gist options
  • Save a10y/d8c646dddc157617f23b to your computer and use it in GitHub Desktop.
Save a10y/d8c646dddc157617f23b to your computer and use it in GitHub Desktop.
Simple python3 web server to view your mining status
#!/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