-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgetConsensusMSC.py
48 lines (42 loc) · 1.5 KB
/
getConsensusMSC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#get balance
import sys
import json
import requests
import urlparse
if len(sys.argv) > 1:
print "Takes a list of MSC consensus sites and outputs a consensus rating with the non-matching balances\nUsage: cat getConsensus.json | python getConsensusMSC.py\n"
exit()
JSON = sys.stdin.readlines()
listSites = json.loads(str(''.join(JSON)))
results = []
for site in listSites['sites']:
#print str(urlparse.urlsplit(site).netloc)
res = requests.get(site)
data = res.json()
#f=open('./'+
results.append({"data": data, "length": len(data), "site": str(urlparse.urlsplit(site).netloc) })
longest = { "length": 0, "site": None }
for site in results:
if site['length'] >= longest['length']:
longest = { "length": site['length'], "site": site['site'] }
addresses = []
for site in results:
if site['site'] == longest['site']:
for summary in site['data']:
addresses.append(summary['address'])
finalcount = []
for address in addresses:
#print type(str(address))
#print address
addrstruct = []
for site in results:
for summary in site['data']:
if str(summary['address']) == str(address):
addrstruct.append({ "address": summary['address'], "balance": float(summary['balance']), "site": site['site'] })
if not all(struct['balance'] == addrstruct[0]['balance'] for struct in addrstruct):
#print addrstruct
if addrstruct != []:
finalcount.append(addrstruct)
consensus = 100*(1-float(len(finalcount))/float(longest['length']))
print json.dumps({ "consensus": consensus, "data": finalcount})
#balance and address