Created
July 11, 2014 21:09
-
-
Save hanksims/4e27e4997ee1f9b84da6 to your computer and use it in GitHub Desktop.
The LoCO Facebook Like Contest Winner Picker!
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 facebook | |
import webbrowser | |
import time | |
import sys | |
import os | |
FACEBOOK_TOKEN = '<YOUR-FACEBOOK-TOKEN>' | |
OBJECT_ID = '<YOUR-OBJECT-ID>' | |
api = facebook.GraphAPI(FACEBOOK_TOKEN) | |
def count(): | |
basic = api.fql('select like_info from photo where object_id=%s' % OBJECT_ID) | |
return basic[0]['like_info']['like_count'] | |
def pick(num=1): | |
winner_ids = api.fql('select user_id from like where object_id=%s ORDER BY rand() LIMIT %s' % (OBJECT_ID, num)) | |
return [a['user_id'] for a in winner_ids] | |
def get_profile(winner_id): | |
winner = api.fql('select name, profile_url from user where uid=%s' % winner_id)[0] | |
return winner | |
if __name__=='__main__': | |
os.system('clear') | |
print('#######################') | |
print( 'NUMBER OF ENTRIES: %s' % count() ) | |
print('#######################') | |
print('') | |
ids = pick(20) | |
for i, id in enumerate(ids): | |
profile = get_profile(id) | |
if i==19: | |
sys.stdout.write('#1: ') | |
sys.stdout.flush() | |
for j in xrange(7): | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
time.sleep(.5) | |
print('\n\n\n\n\n\n') | |
webbrowser.open(profile['profile_url']) | |
else: | |
print( '#%s --> %s' % (20-i,profile['name']) ) | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment