Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Facebook facing library
- from fbchat import Client
- from fbchat.models import *
- from settings import FACEBOOK_SETTINGS
- class facebookface(object):
- """
- Connects to Facebook using the credentials specified. Creates a dictionary of the
- users the authenticating user messaged and returns the userID of a desired
- contact you wish to message.
- """
- def __init__(self):
- self.client = Client(FACEBOOK_SETTINGS.get('email'), FACEBOOK_SETTINGS.get('password'))
- self.username = FACEBOOK_SETTINGS.get('desired_username')
- def get_fb_users(self):
- user_list = [self.client.fetchAllUsers()]
- user_dict = {}
- for user in user_list[0]: # List only predictable when using the zeroth index
- user_dict.update({user.name:user.uid})
- return user_dict[self.username]
- def send_message(self):
- self.client.send(Message(text='Neato! I sent this using a Python library I wrote!'), thread_id=self.get_fb_users(), thread_type=ThreadType.USER)
- self.client.logout()
Add Comment
Please, Sign In to add comment