class Facebook(): def __init__(self, username, password): self.client = Client(username, password) def autoReply(self): income = self.client.listen() author = income.author if onMessage(): self.client.send(Message(text=income.text), thread_id=author) def findFriend(self, name): friends = [] for human in self.client.searchForUsers(name): if human.is_friend: friends.append({ "username": human.name, "uid": human.uid, "photo": human.photo }) return friends def sendMessage(self): self.client.send(Message(text="Hi me!"), thread_id=client.uid, thread_type=ThreadType.USER) def logout(self): self.client.logout()
class TrackerClient: def __init__(self, options, logger, config): self.options = options self.logger = logger self.trackerLogger = TrackerLogger.TrackerLogger(config['db']) self.config = config # let's try to login into that account self.client = Client(self.options['username'], self.options['password'], None, 5, None, logging.CRITICAL) # I'm not sure why, but Facebook API sometimes does return a "historical" data (2-3 hours old) def onChatTimestamp(self, **kwargs): updatedUsers = kwargs['buddylist'].items() self.trackerLogger.log(updatedUsers) for user, timestamp in updatedUsers: userInfo = self.client.fetchUserInfo(user)[user] self.trackerLogger.userdata(userInfo) if ( self.config['env'] == 'dev' ): #and time.time() - int(timestamp) < 60): # to save some unneeded requests self.logger.info('{}: {} updated: {}'.format( self.options['username'], userInfo.name, datetime.datetime.fromtimestamp( int(timestamp)).strftime('%Y-%m-%d %H:%M:%S'))) def listen(self): if (not self.client): self.logger.error('%s: FBChat client not detected!', self.options['username']) return False if (not self.client.isLoggedIn()): self.client.login(self.options['username'], self.options['password']) # monkey patching. not sure if this is a good idea self.client.onChatTimestamp = self.onChatTimestamp self.client.listen()
import data class Jarvis(Client): def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): self.markAsRead(author_id) log.info("Message {} from {} in {}".format(message_object, thread_id, thread_id)) msgText = message_object.text reply = 'Thanks for the messege' if author_id != self.uid: self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) Client = Jarvis(data.email, data.password) Client.listen()
EMAIL = '*****@*****.**' PASSWORD = '******' class EchoBot(Client): def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(author_id, thread_id) self.markAsRead(author_id) print(message_object) # don't reply on our own messages if author_id != self.uid: self.send(Message('fjkdalhflak'), thread_id=thread_id, thread_type=thread_type) client = EchoBot(EMAIL, PASSWORD) client.listen() # # while True: # time.sleep(1.5) # # print(client.fetchUnseen().count(0)) # # print(client.listen()) # print(client.onMessage()) # # if len(client.fetchUnseen()) == 0: # # print('not ') # # else: # # print("Threads: {}".format(client.fetchUserInfo(client.fetchUnseen()[0])))
print(message) client.send(Message(text=message), thread_id=user.uid, thread_type=ThreadType.USER) #search for user objects using a name users = client.searchForUsers('Jeff') user = users[0] print("User's ID: {}".format(user.uid)) print("User's name: {}".format(user.name)) print("User's profile picture URL: {}".format(user.photo)) print("User's main URL: {}".format(user.url)) #This is broken """ class EchoBot(Client): def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(thread_id, message_object.uid) self.markAsRead(thread_id) log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) # If you're not the author, echo if author_id != self.uid: self.send(message_object, thread_id=thread_id, thread_type=thread_type) client.listen() """ input("Press ENTER to send message") send_stock("TSLA")