Created
January 10, 2018 04:06
-
-
Save wgeorgecook/7f98b8504c73aee01ade94847410935f to your computer and use it in GitHub Desktop.
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
# 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