Guest User

Untitled

a guest
Jan 18th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # Facebook facing library
  2.  
  3. from fbchat import Client
  4. from fbchat.models import *
  5.  
  6. from settings import FACEBOOK_SETTINGS
  7.  
  8.  
  9. class facebookface(object):
  10.  
  11. """
  12. Connects to Facebook using the credentials specified. Creates a dictionary of the
  13. users the authenticating user messaged and returns the userID of a desired
  14. contact you wish to message.
  15. """
  16.  
  17. def __init__(self):
  18. self.client = Client(FACEBOOK_SETTINGS.get('email'), FACEBOOK_SETTINGS.get('password'))
  19. self.username = FACEBOOK_SETTINGS.get('desired_username')
  20.  
  21. def get_fb_users(self):
  22. user_list = [self.client.fetchAllUsers()]
  23. user_dict = {}
  24. for user in user_list[0]: # List only predictable when using the zeroth index
  25. user_dict.update({user.name:user.uid})
  26. return user_dict[self.username]
  27.  
  28. def send_message(self):
  29. 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)
  30. self.client.logout()
Add Comment
Please, Sign In to add comment