Created
May 8, 2011 09:08
-
-
Save kvorion/961236 to your computer and use it in GitHub Desktop.
thank your friends for wishing you on your birthday on facebook
This file contains hidden or 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 simplejson as json | |
import urllib2, urllib, string | |
read_token = 'abc | |
write_token = 'def' | |
def GetJsonResponse(requestUrl, content = None): | |
request = urllib2.Request(requestUrl) | |
response = urllib2.urlopen(request, content) | |
result = json.load(response) | |
return result | |
def GetFirstName(facebookId): | |
url = 'https://graph.facebook.com/' + facebookId + '&access_token=' + read_token | |
profileInfoJson = GetJsonResponse(url) | |
first_name = profileInfoJson['first_name'] | |
return first_name | |
def MakeComment(messageId, content): | |
url = 'https://graph.facebook.com/' + messageId + '/comments' | |
print url | |
formPosts = {} | |
formPosts['access_token'] = write_token | |
formPosts['message'] = content | |
data = urllib.urlencode(formPosts) | |
print data | |
f = urllib.urlopen(url, data) | |
print f.read() | |
feedUrl='https://graph.facebook.com/me/feed?access_token=' + read_token + '&limit=100' | |
response = GetJsonResponse(feedUrl) | |
if len(response['data']) != 100: | |
print 'error while retrieving data' | |
else: | |
for counter in range(0, 100): | |
if ('message' in response['data'][counter]) and (string.find(response['data'][counter]['message'].lower(), 'happy') != -1) \ | |
and ('comments' not in response['data'][counter]): | |
first_name = GetFirstName(response['data'][counter]['from']['id']) | |
thanks_message = 'Thanks ' + first_name | |
message_id = response['data'][counter]['id'] | |
print thanks_message | |
MakeComment(message_id, thanks_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment