Created
December 4, 2013 13:11
-
-
Save aantonop/7787199 to your computer and use it in GitHub Desktop.
A script to find bitcoin addresses in Twitter @mentions (replies) responding to my offer to donate bitcoin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import time | |
import re | |
import pycoin.encoding | |
import pickle | |
# Removed security tokens from gist, replaced with XXX. | |
auth = tweepy.OAuthHandler("XXX", "XXX") | |
auth.set_access_token('XXX', 'XXX') | |
api = tweepy.API(auth) | |
bitcoin_addresses = {} | |
request_entries = [] | |
tweet_counter = 0 | |
gap_counter = 0 | |
oldest_id = 507932188366098432 | |
def process(mention): | |
address=re.match(".* (1[a-zA-Z0-9]+)", mention.text) | |
if address: | |
if pycoin.encoding.is_hashed_base58_valid(str(address.group(1).strip())): | |
entry = {'address' : address.group(1), 'user': mention.user.screen_name, 'id': mention.id} | |
print 'adding entry', entry | |
request_entries.append(entry) | |
if address.group(1) not in bitcoin_addresses: | |
bitcoin_addresses[address.group(1)] = entry | |
else: | |
print "duplicate address in request", entry | |
else: | |
print "invalid address in request", address.group(1), mention.text | |
return True | |
else: | |
return False | |
print "Logged in as", api.me().screen_name | |
try: | |
address_file = open('raffle_addresses', 'r') | |
bitcoin_addresses = pickle.load(address_file) | |
address_file.close() | |
except: | |
bitcoin_addresses = {} | |
print "Loaded bitcoin addresses:", len(bitcoin_addresses) | |
for entry in bitcoin_addresses.values(): | |
if entry['id'] < oldest_id: | |
oldest_id = entry['id'] | |
print "Oldest ID:", oldest_id | |
try: | |
for mention in tweepy.Cursor(api.mentions_timeline).items(): | |
time.sleep(4) | |
tweet_counter += 1 | |
if not process(mention): | |
print '.' | |
gap_counter += 1 | |
else: | |
gap_counter = 0 | |
if gap_counter > 50: | |
print "Reached gap counter after", tweet_counter, "tweets" | |
break | |
except: | |
address_file = open('raffle_addresses', 'w') | |
pickle.dump(bitcoin_addresses, address_file) | |
address_file.close() | |
print "Saved", len(bitcoin_addresses), "to file" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment