Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Crypto Pro Reddit giveaway using blockchain to ensure fair lottery with verifiable result
import json, urllib2, hashlib, difflib, datetime
reddit_thread_id = 'e3nf8y'
# get list of all thread comment ids
commment_json = json.load(urllib2.urlopen('' + reddit_thread_id))
# uncomment with comments snapshot file to reproduce results
# commment_json = json.load(open("comments_snapshot.json", "r"))
# calculate sha256 hash for each comment
print("\ncomment hashes:")
comment_hashes = {}
for comment_id in commment_json['data']:
comment_hash = hashlib.sha256(comment_id).hexdigest()
comment_hashes[comment_hash] = comment_id
print("{} -> {}".format(comment_id, comment_hash))
print("\ncomment count: {}".format(len(comment_hashes)))
print("\nblockhain state:")
# get latest hash from bitcoin blockchain
blockchainHash = urllib2.urlopen("").read()
# uncomment and replace with blockchain hash at the time of lottery to reproduce results
#blockchainHash = > replace with block hash at the time of lottery to reproduce results <
print("hash:\t" + blockchainHash)
print("\nclosest hashes:")
matches = difflib.get_close_matches(blockchainHash, comment_hashes.keys(), 10, 0)
for match in matches:
comment_id = comment_hashes[match]
print("{} -> {}".format(match, comment_id))
print("\nreddit links:")
for match in matches:
comment_id = comment_hashes[match]
print("{}/thread/{}".format(reddit_thread_id, comment_id))
# now pick first comment link that passes the giveaway rules (OP's comments are not included in giveaway)
print("\nHappy belated Thanksgiving from Crypto Pro team!\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.