Skip to content

Instantly share code, notes, and snippets.

@s4w3d0ff
Last active June 21, 2019 15:47
Show Gist options
  • Save s4w3d0ff/615c9674ddf194e9a4e0 to your computer and use it in GitHub Desktop.
Save s4w3d0ff/615c9674ddf194e9a4e0 to your computer and use it in GitHub Desktop.
Opens a bitcoin.conf and puts contents into a dict
import os
def readCfg(location):
# Make sure file exists...
if not os.path.exists(location):
return False
with open(location) as f:
cfg= {}
for line in f:
line = line.strip()
# Ignore invalid lines
if line and not line.startswith("#") and '=' in line:
cfg[line.split('=', 1)[0]] = line.split('=', 1)[1]
return cfg
if __name__ == "__main__":
cfg = readCfg('/home/user/.bitcoin/bitcoin.conf')
print(" %s ( :3 )" % cfg['rpcpassword'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment