Created
October 12, 2014 18:49
-
-
Save mavidser/c59b8294cd0260268661 to your computer and use it in GitHub Desktop.
Get facebook status of friends containing the given keywords.
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 sys | |
import json | |
import Queue | |
import threading | |
import requests | |
import ConfigParser | |
from requests_oauthlib import OAuth1 | |
def get_data(query): | |
Config = ConfigParser.ConfigParser() | |
Config.read("config.ini") | |
fbdict=set() | |
def facebook(q, keyword): | |
def extract_status(args): | |
for i in args['data']: | |
q = {} | |
if i['type'] == 'status': | |
try: | |
message = i['message'] | |
except: | |
message = '' | |
user = i['from']['name'] | |
userhref = 'https://facebook.com/' + i['from']['id'] | |
fbdict.add((message,user,userhref)) | |
access_token = Config.get('Facebook', 'access_token') | |
url = 'https://graph.facebook.com/me/home?q='+keyword+'&access_token='+access_token | |
result = requests.get(url) | |
extract_status(result.json()) | |
t={} | |
for i in query: | |
t[i] = threading.Thread(target=facebook, args=('d',i)) | |
t[i].daemon = True | |
t[i].start() | |
for i in query: | |
t[i].join() | |
for count,i in enumerate(fbdict): | |
try: | |
print '[',count,'] -',i[1],':',i[0],'\n' | |
except: | |
pass | |
query=sys.argv[1:] | |
result = get_data(query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment