Skip to content

Instantly share code, notes, and snippets.

Embed
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('https://api.pushshift.io/reddit/submission/comment_ids/' + 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("https://blockchain.info/q/latesthash").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("time:\t{}".format(datetime.datetime.now()))
print("\nclosest hashes:")
# https://docs.python.org/3/library/difflib.html#difflib.get_close_matches
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("https://www.reddit.com/r/Bitcoin/comments/{}/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)
# https://www.reddit.com/r/Bitcoin/comments/e3nf8y/were_giving_away_an_apple_watch_5_as_a_thank_you
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.