Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nightminer.py #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions nightminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# Scrypt Algorithm - http://www.tarsnap.com/scrypt/scrypt.pdf
# Scrypt Implementation - https://code.google.com/p/scrypt/source/browse/trunk/lib/crypto/crypto_scrypt-ref.c

import base64, binascii, json, hashlib, hmac, math, socket, struct, sys, threading, time, urlparse
import base64, binascii, json, hashlib, hmac, math, socket, struct, sys, threading, time, urllib.parse

# DayMiner (ah-ah-ah), fighter of the...
USER_AGENT = "NightMiner"
Expand Down Expand Up @@ -324,10 +324,10 @@ def set_scrypt_library(library = SCRYPT_LIBRARY_AUTO):
elif library == SCRYPT_LIBRARY_AUTO:
try:
set_scrypt_library(SCRYPT_LIBRARY_LTC)
except Exception, e:
except Exception as e:
try:
set_scrypt_library(SCRYPT_LIBRARY_SCRYPT)
except Exception, e:
except Exception as e:
set_scrypt_library(SCRYPT_LIBRARY_PYTHON)

else:
Expand Down Expand Up @@ -623,15 +623,15 @@ def _handle_incoming_rpc(self):
(line, data) = data.split('\n', 1)
else:
chunk = self._socket.recv(1024)
data += chunk
data += chunk.decode()
continue

log('JSON-RPC Server > ' + line, LEVEL_PROTOCOL)

# Parse the JSON
try:
reply = json.loads(line)
except Exception, e:
except Exception as e:
log("JSON-RPC Error: Failed to parse JSON %r (skipping)" % line, LEVEL_ERROR)
continue

Expand All @@ -641,7 +641,7 @@ def _handle_incoming_rpc(self):
if 'id' in reply and reply['id'] in self._requests:
request = self._requests[reply['id']]
self.handle_reply(request = request, reply = reply)
except self.RequestReplyWarning, e:
except self.RequestReplyWarningas as e:
output = e.message
if e.request:
output += '\n ' + e.request
Expand All @@ -665,7 +665,7 @@ def send(self, method, params):
with self._lock:
self._requests[self._message_id] = request
self._message_id += 1
self._socket.send(message + '\n')
self._socket.send((message + '\n').encode())

log('JSON-RPC Server < ' + message, LEVEL_PROTOCOL)

Expand Down Expand Up @@ -807,7 +807,7 @@ def run(job):
self.send(method = 'mining.submit', params = params)
log("Found share: " + str(params), LEVEL_INFO)
log("Hashrate: %s" % human_readable_hashrate(job.hashrate), LEVEL_INFO)
except Exception, e:
except Exception as e:
log("ERROR: %s" % e, LEVEL_ERROR)

thread = threading.Thread(target = run, args = (self._job, ))
Expand All @@ -819,7 +819,7 @@ def serve_forever(self):
'''Begins the miner. This method does not return.'''

# Figure out the hostname and port
url = urlparse.urlparse(self.url)
url = urllib.parse.urlparse(self.url)
hostname = url.hostname or ''
port = url.port or 9333

Expand Down Expand Up @@ -918,14 +918,14 @@ def test_subscription():
else:
try:
(username, password) = options.userpass.split(':')
except Exception, e:
except Exception as e:
message = 'Could not parse username:password for -O/--userpass'

# Was there an issue? Show the help screen and exit.
if message:
parser.print_help()
print
print message
print(message)
sys.exit(1)

# Set the logging level
Expand Down