From 31b45cad1562828e8bb0a5637709c7458c86a630 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Fri, 14 Sep 2018 20:27:19 +0530 Subject: [PATCH] Update --- getJson.py | 44 +++++++++++++++++++++++++++++--------------- main.py | 13 ++++++++++++- test.py | 12 ++++++++++++ 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 test.py diff --git a/getJson.py b/getJson.py index 78295b5..aefdd8f 100644 --- a/getJson.py +++ b/getJson.py @@ -2,29 +2,43 @@ import requests import json import subprocess +JsonAddress = "ocZXNtzpiUqBvzQorjAKmZ5MhXxGTLKeSH" + +def searchDict(dicArr,key,val): + for i in range(len(dicArr)): + if(dicArr[i][key]==val): + return i + return -1 + +def readUnitFromBlockchain(txid): + rawtx = subprocess.check_output(["flo-cli","--testnet", "getrawtransaction", str(txid)]) + rawtx = str(rawtx) + rawtx = rawtx[2:-3] + tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)]) + content = json.loads(tx) + text = content['floData'] + return text + def getJsonData(): - r = requests.get("https://testnet.florincoin.info/ext/getaddress/ocZXNtzpiUqBvzQorjAKmZ5MhXxGTLKeSH") + r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress) data = json.loads(r.content) #print(data) - - def readUnitFromBlockchain(txid): - rawtx = subprocess.check_output(["flo-cli","--testnet", "getrawtransaction", str(txid)]) - rawtx = str(rawtx) - rawtx = rawtx[2:-3] - tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)]) - content = json.loads(tx) - text = content['floData'] - return text - Dapps = [] for i in range(len(data['last_txs'])): if(data['last_txs'][i]['type']=='vin'): content = readUnitFromBlockchain(data['last_txs'][i]['addresses']) #print(content) if content.startswith("text:Dapps"): - print(data['last_txs'][i]['addresses']) + #print(data['last_txs'][i]['addresses']) pos = content.find('{') - Dapps = Dapps + [json.loads(content[pos:])] + app = json.loads(content[pos:]) + i = searchDict(Dapps,'id',app['id']) + if (i!=-1): + del(Dapps[i]) + if ('remove' not in app.keys()): + Dapps = Dapps + [app] + #print(Dapps) + return Dapps - print(Dapps) - return Dapps \ No newline at end of file +apps = getJsonData() +print(apps) \ No newline at end of file diff --git a/main.py b/main.py index d79dd40..ea53566 100755 --- a/main.py +++ b/main.py @@ -11,6 +11,12 @@ import requests JsonAddress = "ocZXNtzpiUqBvzQorjAKmZ5MhXxGTLKeSH" +def searchDict(dicArr,key,val): + for i in range(len(dicArr)): + if(dicArr[i][key]==val): + return i + return -1 + def isConnected(): try: socket.create_connection(("www.github.com", 80)) @@ -40,7 +46,12 @@ def getJsonData(): if content.startswith("text:Dapps"): #print(data['last_txs'][i]['addresses']) pos = content.find('{') - Dapps = Dapps + [json.loads(content[pos:])] + app = json.loads(content[pos:]) + i = searchDict(Dapps,'id',app['id']) + if (i!=-1): + del(Dapps[i]) + if ('remove' not in app.keys()): + Dapps = Dapps + [app] #print(Dapps) return Dapps diff --git a/test.py b/test.py new file mode 100644 index 0000000..bb20097 --- /dev/null +++ b/test.py @@ -0,0 +1,12 @@ +def searchDict(dicArr,key,val): + for i in range(len(dicArr)): + if(dicArr[i][key]==val): + return i + return -1 + +d = [{'id': '1', 'name': 'Alexandria', 'icon': 'Icon/Alexandria.png', 'type': 'Webapp', 'url': 'https://alexandria.io/browser/'}, {'id': '2', 'name': 'AlternateLove', 'icon': 'Icon/AternaLove.png', 'type': 'Cmdline', 'location': 'apps/aternalove', 'exec': './auto-aterna-love.sh', 'github': 'https://github.com/metacoin/aternalove.git'}, {'id': '3', 'name': 'Caltech', 'icon': 'Icon/Caltech.png', 'type': 'Webapp', 'url': 'https://etdb.caltech.edu/browse'}, {'id': '4', 'name': 'Flotorizer', 'icon': 'Icon/Flotorizer.png', 'type': 'Webapp', 'url': 'http://flotorizer.net/'}, {'id': '5', 'name': 'Medici', 'icon': 'Icon/Medici.png', 'type': 'Webapp', 'url': 'https://www.mediciventures.com/'}, {'id': '6', 'name': 'FloSharedSecret', 'icon': 'Icon/SharedSecret.png', 'type': 'Gui', 'location': 'apps/FLO-shared-secret/', 'exec': './FLO_Secret', 'github': 'https://github.com/akhil2015/FLO-shared-secret.git'}, {'id': '7', 'name': 'FloRate', 'icon': 'Icon/Florate.png', 'type': 'Gui', 'location': 'apps/FloRate-Dapp/', 'exec': './Florate', 'github': 'https://github.com/Tarun047/FloRate-Dapp.git'}, {'id': '8', 'name': 'tZero', 'icon': 'Icon/tZero.png', 'type': 'Webapp', 'url': 'https://www.tzero.com/'}, {'id': '9', 'name': 'WorldMood', 'icon': 'Icon/WorldMood.png', 'type': 'Webapp', 'url': 'http://worldmood.io/'}, {'id': '10', 'name': 'Xcertify', 'icon': 'Icon/Xcertify.png', 'type': 'Cmdline', 'location': 'apps/Xcertify/', 'exec': './xcertify', 'github': 'https://github.com/akhil2015/Xcertify.git'}] +del(d[1]) +print(d) +i = searchDict(d,'id','4') +if(i!=-1): + print(i)