Fixed indent and node running script.

This commit is contained in:
Fillerino 2017-09-05 20:56:29 +02:00
parent 25e083be75
commit d05ad11855
2 changed files with 18 additions and 8 deletions

View file

@ -16,4 +16,4 @@
- git: repo=https://github.com/lbryio/lighthouse.git dest=~/lighthouse - git: repo=https://github.com/lbryio/lighthouse.git dest=~/lighthouse
- raw: cd ~/lighthouse/decoder && pip install -r requirements.txt && screen -S decoder -d -m python decoder.py && sleep 2 - raw: cd ~/lighthouse/decoder && pip install -r requirements.txt && screen -S decoder -d -m python decoder.py && sleep 2
- raw: cd ~/lighthouse && yarn install --production=false && yarn global add forever - raw: cd ~/lighthouse && yarn install --production=false && yarn global add forever
- raw: forever start -c "npm run prod" ~/lighthouse - raw: cd ~/lighthouse && yarn run build && cd dist && forever start index.js

View file

@ -1,9 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json import json
from bitcoinrpc.authproxy import AuthServiceProxy from bitcoinrpc.authproxy import AuthServiceProxy
from lbryschema.decode import smart_decode from lbryschema.decode import smart_decode
from flask import Flask, url_for from flask import Flask, url_for
app = Flask(__name__) app = Flask(__name__)
def get_lbrycrdd_connection_details(): def get_lbrycrdd_connection_details():
with open('config.json', 'r') as f: with open('config.json', 'r') as f:
config = json.load(f) config = json.load(f)
@ -11,13 +14,16 @@ def get_lbrycrdd_connection_details():
rpc_pass = config['rpc_password'] rpc_pass = config['rpc_password']
rpc_port = config['rpc_port'] rpc_port = config['rpc_port']
rpc_url = config['rpc_url'] rpc_url = config['rpc_url']
return "http://%s:%s@%s:%i" % (rpc_user, rpc_pass, rpc_url, rpc_port) return 'http://%s:%s@%s:%i' % (rpc_user, rpc_pass, rpc_url,
rpc_port)
@app.errorhandler(500) @app.errorhandler(500)
def internal_error(error): def internal_error(error):
return 'error when decoding claims' return 'error when decoding claims'
@app.route('/claim_decode/<txid>/<nout>') @app.route('/claim_decode/<txid>/<nout>')
def api_decode(txid, nout): def api_decode(txid, nout):
connection_string = get_lbrycrdd_connection_details() connection_string = get_lbrycrdd_connection_details()
@ -29,21 +35,25 @@ def api_decode(txid, nout):
claim = claim_out claim = claim_out
break break
if claim: if claim:
converted = "".join([chr(ord(i)) for i in claim['value']]) converted = ''.join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted) # Decode the claims and dump them back to logstash plugin decoded = smart_decode(converted)
claim['value'] = decoded.claim_dict claim['value'] = decoded.claim_dict
return json.dumps(claim) return json.dumps(claim)
@app.route('/claim_decodeinv/<claimid>') @app.route('/claim_decodeinv/<claimid>')
def api_decodebyclaim(claimid): def api_decodebyclaim(claimid):
connection_string = get_lbrycrdd_connection_details() connection_string = get_lbrycrdd_connection_details()
rpc = AuthServiceProxy(connection_string) rpc = AuthServiceProxy(connection_string)
claim = rpc.getvalueforname(claimid) claim = rpc.getvalueforname(claimid)
if claim: if claim:
converted = "".join([chr(ord(i)) for i in claim['value']]) converted = ''.join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted) # Decode the claims and dump them back to logstash plugin decoded = smart_decode(converted)
claim['value'] = decoded.claim_dict claim['value'] = decoded.claim_dict
return json.dumps(claim) return json.dumps(claim)
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='127.0.0.1') app.run(host='127.0.0.1')