Skip to content

Instantly share code, notes, and snippets.

@random-zebra
Created March 14, 2019 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save random-zebra/186835d1f9a24259946ecaa0d316d284 to your computer and use it in GitHub Desktop.
Save random-zebra/186835d1f9a24259946ecaa0d316d284 to your computer and use it in GitHub Desktop.
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
try:
import http.client as httplib
except ImportError:
import httplib
import os
RPC_IP = "127.0.0.1"
RPC_PORT = 45458
RPC_USER = "myUsername"
RPC_PASSWD = "myPassword"
class PIVXnode:
"""
RPC Connection to PIVX wallet
"""
def __init__(self):
self.rpc_url = "http://%s:%s@%s:%d" % (RPC_USER, RPC_PASSWD, RPC_IP, RPC_PORT)
self.httpConnection = httplib.HTTPConnection(RPC_IP, RPC_PORT, timeout=20)
self.conn = AuthServiceProxy(self.rpc_url, timeout=1000, connection=self.httpConnection)
def connect(self):
self.httpConnection.connect()
def disconnect(self):
self.httpConnection.close()
def readFromFile(filename):
"""
Reads a csv file returning a list of dictionaries
"""
csv_list = []
try:
import csv
datafile_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
with open(datafile_name, 'r') as data_file:
reader = csv.DictReader(data_file)
line_count = 0
for row in reader:
if line_count != 0:
csv_list.append(row)
line_count += 1
return csv_list
except Exception as e:
errorMsg = "error reading file %s" % filename
print(errorMsg)
print(e)
def writeToFile(data, filename):
"""
Writes a list of dictionaries as csv rows to a file
"""
try:
import csv
datafile_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
with open(datafile_name, 'w+') as data_file:
writer = csv.writer(data_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(list(data[0].keys()))
for d in data:
writer.writerow(list(d.values()))
except Exception as e:
errorMsg = "error writing file %s" % filename
print(errorMsg)
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment