Skip to content

Instantly share code, notes, and snippets.

@wgeorgecook
Created January 10, 2018 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgeorgecook/7f98b8504c73aee01ade94847410935f to your computer and use it in GitHub Desktop.
Save wgeorgecook/7f98b8504c73aee01ade94847410935f to your computer and use it in GitHub Desktop.
# 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment