Guest User

steemit_lottery

a guest
Jul 19th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import json, re, requests, collections
  2. from piston.steem import Steem
  3.  
  4. def extraction(random, votes):
  5.     tot_rshares = sum(map(int,[x['rshares'] for x in votes]))
  6.     tickets = {}
  7.     for vote in votes:
  8.         tickets[vote['voter']] = float(vote['rshares'])/tot_rshares
  9.     tot = 0
  10.     for voter in collections.OrderedDict(sorted(tickets.items())):
  11.         tot += tickets[voter]
  12.         if tot > random:
  13.             return(voter)
  14.  
  15. blockhash = json.loads((requests.get('https://blockchain.info/it/block-height/422321?format=json').text))['blocks'][0]['hash']
  16. random = int(blockhash,16)/16.**(64-len(re.match('[0]*',blockhash).group(0)))
  17. votes = Steem().get_content("@rodomonte/social-attack-on-steemit").active_votes
  18.  
  19. print(extraction(random, votes))
Advertisement
Add Comment
Please, Sign In to add comment