def __init__(self): print "Enter your GMAIL details:" self.auth = base64.encodestring('%s:%s'%(raw_input('Username: '******'read_stream','manage_notifications','read_mailbox','read_requests','user_status'] fb.authenticate() last_check1 = time.time() - INTERVAL * 60 # GMAIL check last_check2 = time.time() - INTERVAL * 60 + 30 # FB check fCounter = 0 gCounter = 0 while True: if time.time() - last_check1 > 60 * INTERVAL: last_check1 = time.time() gCounter = self.count(self.getfeed(self.auth)) print "Unread Mails on GMAIL :", gCounter writeSer(GMAIL,str(gCounter)) if time.time() - last_check2 > 60 * INTERVAL: last_check2 = time.time() userId = fb.fql("SELECT uid,name FROM user WHERE uid = me()") notify = fb.fql("SELECT notification_id,created_time,title_text FROM notification WHERE recipient_id = me() AND is_unread = 1") mail = fb.fql("SELECT name,unread_count FROM mailbox_folder WHERE folder_id = 0 AND viewer_id = me()") if len(mail): fCounter += 1 if len(notify): fCounter += len(notify) writeSer(FB,fCounter) print "Notifiactions on FB :",fCounter fCounter = 0
def queryFB(self): #FQL's to get the notification self.userId = fb.fql("SELECT uid,name FROM user WHERE uid = me()") self.notify = fb.fql( "SELECT notification_id,created_time,title_text FROM notification WHERE recipient_id = me() AND is_unread = 1" ) self.mail = fb.fql( "SELECT name,unread_count FROM mailbox_folder WHERE folder_id = 0 AND viewer_id = me()" )
def getEmail(): friends = fbconsole.fql("SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())") cont = 0 naoPegou = [] for entry in feed.entry: if entry.title.text: #print entry.title.text pegou = 1 for amigo in friends: if entry.title.text == amigo["name"]: print "Mudando foto: "+str(amigo["uid"]) + " " + (amigo["name"].encode("utf-8")).decode("utf-8") profile_pic = "https://graph.facebook.com/"+str(amigo["uid"])+"/picture?type=large" try: urlretrieve(profile_pic, str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg") except: print "Erro ao tentar modificar a foto de " + (amigo["name"].encode("utf-8")).decode("utf-8") continue client.change_photo(str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg",entry,"image/jpeg") cont += 1 os.remove(str(amigo["name"].encode("utf-8")).decode("utf-8")+".jpg") pegou = 0 break if pegou == 1: naoPegou.append(entry.title.text) print "Foram pegos " + str(cont) + " contatos.\n" for nome in naoPegou: print nome
def bdaythank(post_limit, comment=None): ''' Likes and comments all posts automatically ''' fbconsole.AUTH_SCOPE = [ 'publish_actions', 'read_stream', 'user_actions.news', 'publish_stream' ] fbconsole.authenticate() query = fbconsole.fql( "SELECT post_id FROM stream WHERE source_id=me() LIMIT %s" % post_limit) for post in query: if comment: comment_id = requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/comments/?access_token=" + fbconsole.ACCESS_TOKEN + "&message=%s" % comment) print "Comment id: " + comment_id.text requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/likes/?access_token=" + fbconsole.ACCESS_TOKEN + "&method=POST") print "$ Liked" fbconsole.logout()
def _createScoreBoard(self): # get friends list fb_result = fb.fql('SELECT uid, name FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())') # insert me fb_result.extend([{'uid':self._parent._pilot.id, 'name':'You'}]) # Pornchanok id # insert some fake data fb_result.extend([{'uid':'100000533319275', 'name':'Pornchanok'}]) # Pornchanok id # fb_result.extend([{'uid':'247059255488681', 'name':'Test User #1'}]) # friend of Test User #1 # fb_result.extend([{'uid':'252287594960325', 'name':'Test User #2'}]) # friend of Test User #2 friends_that_use_this_app = [entry['uid'] for entry in fb_result] data = bytes('{"type":"action","value":"get","target":"score_board","data":%s}' % anyjson.serialize(friends_that_use_this_app), 'utf-8') result = ConnectionManager.send(data) if ConnectionManager.isSuccessfulResponse(result): self._friends = [] # data = [d['name'] = fd['name'] for d in result['data'] for fd in fb_result if fd['uid'] == d['id']] data = [] for d in result['data']: for fd in fb_result: if fd['uid'] == d['id']: d['name'] = fd['name'] data.append(d) for f in result['data']: self._friends.append(Pilot(f['id'], f['name'], f['score'], f['wave'], f['time'])) w, h = (400, 600) rowData = [('', 'Name', 'Score', 'Wave')] rowData.extend([(str(i), pilot.name, str(pilot.bestScore), str(pilot.bestWave)) for i, pilot in enumerate(self._friends, 1)]) columnWidth = [30, 200, 75, 75] self._scoreBoard = Table(self, w, h, rowData, columnWidth, title='Score board') self.addElement(self._scoreBoard) self.addEventListener(self._scoreBoard.handleEvent)
def commentlikepost(post_limit): ''' Likes and comments post ''' fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'read_stream'] fbconsole.authenticate() #status = fbconsole.post('/me/feed', {'message':'Hello from python s script'}) fbconsole.authenticate() query = fbconsole.fql("SELECT actor_id, post_id FROM stream WHERE source_id=me() LIMIT %s" % post_limit) print query for post in query: r = requests.get('https://graph.facebook.com/%s' % post['actor_id']) user = json.loads(r.text) comment = '%s %s: Like and comment from python script! :)' % (user['first_name'] , user['last_name']) print comment #Reply comment comment_id = requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/comments/?access_token=" + fbconsole.ACCESS_TOKEN + "&message=%s" % comment ) print "Comment id: " + comment_id.text #Like the post requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/likes/?access_token=" + fbconsole.ACCESS_TOKEN + "&method=POST") print "Liked" fbconsole.logout()
def notification(): print 'fetching your unread notifications.... \n ' notify = fbconsole.fql("SELECT is_unread,title_text FROM notification WHERE recipient_id=me()") for i in notify: list(i) a = i.values() if a[1]==1: print a[0]+'\n'
def get_comments(post_id): comment_data = fbconsole.fql("SELECT text FROM comment WHERE post_id = %s" %(post_id)) no_of_comments = len(comment_data) comments = [] for y in range(0, no_of_comments - 1): comments.append(comment_data[y]['text']) return comments
def get_comments_poster(post_id): comment_data = fbconsole.fql("SELECT fromid FROM comment WHERE post_id = %s" %(post_id)) no_of_comments = len(comment_data) posters = [] for z in range(0, no_of_comments): posters.append(get_name(str(comment_data[z]['fromid']))) return posters
def fb_access(): """ logs into Facebook account and asks for permission. Further the music names are extracted from the profile""" fbconsole.AUTH_SCOPE = ['user_likes','publish_checkins' ] fbconsole.authenticate() music = fbconsole.fql("SELECT music FROM user WHERE uid=me()") music_names(music) fbconsole.logout()
def get_posts(): last5_data = fbconsole.fql("SELECT status_id, message from status WHERE uid = me() LIMIT 5") print last5_data last5_status_id = [] last5_status_message = [] for x in range(0,5): last5_status_id.append(str(last5_data[0]["status_id"])[:-1]) last5_status_message.append(last5_data[0]["message"]) return last5_status_message
def notification(): print 'fetching your unread notifications.... \n ' notify = fbconsole.fql( "SELECT is_unread,title_text FROM notification WHERE recipient_id=me()" ) for i in notify: list(i) a = i.values() if a[1] == 1: print a[0] + '\n'
def __init__(self): print "Enter your GMAIL details:" self.auth = base64.encodestring( '%s:%s' % (raw_input('Username: '******'read_stream', 'manage_notifications', 'read_mailbox', 'read_requests', 'user_status' ] fb.authenticate() last_check1 = time.time() - INTERVAL * 60 # GMAIL check last_check2 = time.time() - INTERVAL * 60 + 30 # FB check fCounter = 0 gCounter = 0 while True: if time.time() - last_check1 > 60 * INTERVAL: last_check1 = time.time() gCounter = self.count(self.getfeed(self.auth)) print "Unread Mails on GMAIL :", gCounter writeSer(GMAIL, str(gCounter)) if time.time() - last_check2 > 60 * INTERVAL: last_check2 = time.time() userId = fb.fql("SELECT uid,name FROM user WHERE uid = me()") notify = fb.fql( "SELECT notification_id,created_time,title_text FROM notification WHERE recipient_id = me() AND is_unread = 1" ) mail = fb.fql( "SELECT name,unread_count FROM mailbox_folder WHERE folder_id = 0 AND viewer_id = me()" ) if len(mail): fCounter += 1 if len(notify): fCounter += len(notify) writeSer(FB, fCounter) print "Notifiactions on FB :", fCounter fCounter = 0
def music(request): fbconsole.AUTH_SCOPE = ['user_likes','publish_checkins' ] fbconsole.authenticate() music = fbconsole.fql("SELECT music FROM user WHERE uid=me()") music_list = music[0].values() for name in music_list: #fetch music names music_name = (choice(name.split(','))).encode('utf-8') for url in search('%s gaana' %music_name, stop=1): #validating if the music are avalialble if re.search(ur'http://gaana.com', url, re.UNICODE): webbrowser.open_new(url) break
def music(request): fbconsole.AUTH_SCOPE = ['user_likes', 'publish_checkins'] fbconsole.authenticate() music = fbconsole.fql("SELECT music FROM user WHERE uid=me()") music_list = music[0].values() for name in music_list: #fetch music names music_name = (choice(name.split(','))).encode('utf-8') for url in search('%s gaana' % music_name, stop=1): #validating if the music are avalialble if re.search(ur'http://gaana.com', url, re.UNICODE): webbrowser.open_new(url) break
def get(self): global own_likes global friend_tuples global my_loc user = fbconsole.get('/me') name = user['first_name'] uid = user['id'] client = tornado.httpclient.HTTPClient() friend_tuples = fbconsole.fql("SELECT name,uid FROM user WHERE uid IN " "(SELECT uid2 FROM friend WHERE uid1 = me())") own_likes = fbconsole.fql("SELECT page_id FROM page_fan WHERE uid = %s" % uid) own_locale = fbconsole.fql("SELECT current_location FROM user WHERE uid = %s" % uid) my_loc = own_locale[0]['current_location']['name'] #gather own locale city = own_locale[0]['current_location']['city'] city = city.replace(' ',',') # client = tornado.httpclient.AsyncHTTPClient() # client.fetch("http://api.eventful.com/rest/events/search?" + \ # urllib.urlencode({"app_key": "5zPbkgmCjXhLpHT9", "keywords":"movies", "location":city}), # callback=self.on_movie_response) self.render("main.html", name = name);
def build3(self, child): last5_data = fbconsole.fql("SELECT status_id, message from status WHERE uid = me() LIMIT 5") last5_status_id = [] last5_status_message = [] for x in range(0,5): last5_status_id.append(str(last5_data[x]["status_id"])[:-1]) last5_status_message.append(last5_data[x]["message"]) posts = last5_status_message subroot = BoxLayout(orientation="vertical") for x in range(0,5): indv_post = Button(text=posts[x]) subroot.add_widget(indv_post) return subroot
def photos(): fb.AUTH_SCOPE = ['publish_stream', 'user_photos', 'friends_photos'] fql = '''select object_id, owner, src_big from photo where aid in (select aid from album where name="Profile Pictures" and owner in (select uid2 from friend where uid1=me() ))''' fb.authenticate() print 'autenticou' links = fb.fql(fql) for photo_links in links: uid = photo_links['owner'] photo_id = photo_links['src_big'] for key, value in photo_links.items(): if key == 'src_big': http_client.fetch(value, buscar(uid, photo_id)) print photo_id baixar.add(photo_id) ioloop.IOLoop.instance().start()
def Facebook(): """Used to Control KFM game page""" global PARAMS global FRIENDS if PARAMS['male']==False: """If params have not been set the (equal to false) set params""" PARAMS = {k:(request.args[k] if k in request.args else'off') for k in PARAMS.keys()} if FRIENDS == {}: """If Friends are empty Populate Friends""" SqL_Filter="" if PARAMS['male']=='on' and PARAMS['female']!='on': SqL_Filter+=(" and sex='male'") if PARAMS['female']=='on' and PARAMS['male']!='on': SqL_Filter+=(" and sex='female'") if PARAMS['relationship']!='on' and PARAMS['single']=='on': SqL_Filter+=(" and relationship_status='single'") if PARAMS['relationship']=='on' and PARAMS['single']!='on': SqL_Filter+=(" and relationship_status<>'single'") """Uses fbconsole to make fql query to facebook graph to get name and Profile Pic of people who fit within the query""" FRIENDS = fbconsole.fql("SELECT name, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" +SqL_Filter) random.shuffle(FRIENDS) """Shuffle Friends list to make them random every time""" """render Facebook.html with three friends's name and profile pics being displayed""" return render_template('Facebook.html',friend_one=FRIENDS[0], friend_two=FRIENDS[1], friend_three=FRIENDS[2]) if 'Kill' in request.args: if 3 == len(set(request.args.values())): """IF Kill Flirt Marry has been submitted check if all values are different""" FRIENDS=FRIENDS[3:] """remove first three firends if submition follows the rules""" if len(FRIENDS)<3: """If Friends list is less than three the game is over and takes you back to the submition page""" easygui.msgbox("Try another filter or log onto a friends facebook",title="Congradulations", ok_button="Finish") return redirect(url_for('index_page')) """update pictures and names with next three friends""" return render_template('Facebook.html',friend_one=FRIENDS[0], friend_two=FRIENDS[1], friend_three=FRIENDS[2]) else: """If mutliple catagories given to one person""" easygui.msgbox("One Catagory for each Person",title="Try Agian", ok_button="Redo") return render_template('Facebook.html',friend_one=FRIENDS[0], friend_two=FRIENDS[1], friend_three=FRIENDS[2])
def getPosts(): fb_data = fbconsole.fql("SELECT post_id, actor_id, message, message_tags, attachment, likes, comments, permalink, type, target_id, place, created_time FROM stream WHERE source_id = " + str(id_fb) + " and created_time > " + str(start_interval) + " AND created_time < " + str(end_interval)) return fb_data
def unread(): print 'showing number of unread messages in your inbox.... \n' unread = fbconsole.fql("SELECT unread_count FROM mailbox_folder WHERE folder_id =0 AND viewer_id =me()") print ' %s unread message(s) in your inbox' %(unread[0].values())
def run(self): fbconsole.AUTH_SCOPE = ['user_photos', 'friends_photos', 'user_videos'] fbconsole.authenticate() print "Getting mutual friends" mutual_friends = fbconsole.get('/me/mutualfriends/%s' % \ self.target) friendlist = "(%s)" % ','.join( ["'%s'" % user['id'] for user in mutual_friends['data']] ) time.sleep(1) print "Getting albums" albums = fbconsole.fql(""" SELECT aid, name, owner FROM album WHERE owner IN %s """ % friendlist) for album in albums: time.sleep(1) sys.stdout.write('.') sys.stdout.flush() photos = fbconsole.fql(""" SELECT src_big, link, caption, images, pid, created FROM photo WHERE pid IN ( SELECT pid FROM photo_tag WHERE pid IN ( SELECT pid FROM photo WHERE aid = '%s' ) AND subject = '%s' ) """ % (album['aid'], self.target) ) if len(photos) > 0: print "\nIn: '%s' by %d:" % (album['name'], album['owner']) for photo in photos: biggest_image = 0 biggest_dim = 0 for i, image in enumerate(photo['images']): if biggest_dim < image['height']: biggest_dim = image['height'] biggest_image = i image_url = photo['images'][biggest_image]['source'] file_part = image_url.split('/')[-1] file_path = "%s/%s" % (self.destination, "%s_%s_%s" % \ (album['owner'], album['aid'], file_part)) print "Retrieving %s" % image_url try: # Grab the photo. response = urllib2.urlopen(image_url) image_data = response.read() newfile = open(file_path, 'w') newfile.write(image_data) newfile.flush() newfile.close() # Set file modification/creation time to the original # upload date. if photo['created'] > 666666: print "creation date is %d" % photo['created'] os.utime(file_path, (photo['created'], photo['created'])) except urllib2.HTTPError as (e): print "Error received during image grab: %s" % e.read()
def unread(): print 'showing number of unread messages in your inbox.... \n' unread = fbconsole.fql( "SELECT unread_count FROM mailbox_folder WHERE folder_id =0 AND viewer_id =me()" ) print ' %s unread message(s) in your inbox' % (unread[0].values())
#!/usr/bin/python import fbconsole fbconsole.APP_ID = '177876045644347' fbconsole.AUTH_SCOPE = [ 'publish_stream', 'publish_checkins', 'read_stream', 'offline_access' ] fbconsole.authenticate() me = fbconsole.get('/me') my_id = me['id'] statuses = fbconsole.fql("SELECT status_id,message FROM status WHERE uid=me()") for status in statuses: s = fbconsole.get('/%s' % status['status_id']) print my_id + '_' + s['id'] print s['message'] print( '#######################################################################################' )
def read_comments(self, post_id, min_time): return fb.fql('SELECT text FROM comment WHERE ' + 'post_id="' + post_id + '" AND fromid=' + self.actor_id + ' AND time>{}'.format(min_time))
def read_stream(self, min_time): return fb.fql('SELECT post_id, message FROM stream WHERE ' + 'source_id=' + self.group_id + ' AND actor_id=' + self.actor_id + ' AND created_time>{}'.format(min_time))
def get_updatetime(self): update_info = fb.fql('SELECT update_time FROM group WHERE ' + 'gid=' + self.group_id) return long(update_info[0]['update_time'])
''' Script to export facebook contacts to a CSV based on the fbconsole tool ''' import fbconsole as fb import json,csv fb.AUTH_SCOPE=['friends_education_history','friends_location','friends_work_history'] fb.authenticate() friends=fb.fql("select uid,first_name,last_name,locale,affiliations,contact_email,email,current_address, current_location,birthday,friend_count,mutual_friend_count,hometown_location,languages,name,sex, website,education,work from user where uid in (select uid2 from friend where uid1=me())") #uids=[i['uid'] for i in friends] with open('fb_friends.json','w') as ofile: json.dump(friends,ofile) fb.logout() #destroy locally stored auth token names=[(i['first_name'],i['last_name']) for i in friends] with open('fb_names2012.csv','w') as ofile: writer=csv.writer(ofile) writer.writerow(('First Name','Last Name')) for name in names: try: writer.writerow(name) except UnicodeEncodeError: print('Name %s %s could not be written to CSV'%name)
def get_name(id): userid_data = fbconsole.fql("SELECT name FROM profile WHERE id = %s" %(id)) print userid_data[0]["name"]
def queryFB(self): #FQL's to get the notification self.userId = fb.fql("SELECT uid,name FROM user WHERE uid = me()") self.notify = fb.fql("SELECT notification_id,created_time,title_text FROM notification WHERE recipient_id = me() AND is_unread = 1") self.mail = fb.fql("SELECT name,unread_count FROM mailbox_folder WHERE folder_id = 0 AND viewer_id = me()")
#!/usr/bin/python import fbconsole fbconsole.APP_ID = '177876045644347' fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'read_stream', 'offline_access'] fbconsole.authenticate() me = fbconsole.get('/me') my_id = me['id'] statuses = fbconsole.fql("SELECT status_id,message FROM status WHERE uid=me()") for status in statuses: s = fbconsole.get('/%s' % status['status_id']) print my_id+'_'+s['id'] print s['message'] print('#######################################################################################')