threads = client.fetchThreadList() # Fetches the next 10 threads threads += client.fetchThreadList(offset=20, limit=10) print("Threads: {}".format(threads)) # Gets the last 10 messages sent to the thread messages = client.fetchThreadMessages(thread_id='<thread id>', limit=10) # Since the message come in reversed order, reverse them messages.reverse() # Prints the content of all the messages for message in messages: print(message.text) # If we have a thread id, we can use `fetchThreadInfo` to fetch a `Thread` object thread = client.fetchThreadInfo('<thread id>')['<thread id>'] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # `searchForThreads` searches works like `searchForUsers`, but gives us a list of threads instead thread = client.searchForThreads('<name of thread>')[0] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # Here should be an example of `getUnread`
print("user's photo: {}".format(user.photo)) print("Is user client's friend: {}".format(user.is_friend)) # Fetches a list of the 20 top threads you're currently chatting with threads = client.fetchThreadList() # Fetches the next 10 threads threads += client.fetchThreadList(offset=20, limit=10) print("Threads: {}".format(threads)) # Gets the last 10 messages sent to the thread messages = client.fetchThreadMessages(thread_id="<thread id>", limit=10) # Since the message come in reversed order, reverse them messages.reverse() # Prints the content of all the messages for message in messages: print(message.text) # If we have a thread id, we can use `fetchThreadInfo` to fetch a `Thread` object thread = client.fetchThreadInfo("<thread id>")["<thread id>"] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # `searchForThreads` searches works like `searchForUsers`, but gives us a list of threads instead thread = client.searchForThreads("<name of thread>")[0] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # Here should be an example of `getUnread`
username = str(raw_input("Username: "******"Want to save your data as a .Zip file y/n?: ")) username = str( raw_input("want to download messages from a specific friend type(y/n): ")) if username.lower() == 'y': names = str( raw_input( "Name of that friends separated by a comma like - satyendra pandey, Narendra pandey--: " )) names = names.split(',') for name in names: thread = client.searchForThreads(name)[0] do_rest(thread, client) if zipping.lower() == 'y': make_zip() else: num = int(raw_input("Number of friends from top of your chatlist:")) if num < 20: threads = client.fetchThreadList(limit=num) else: threads = client.fetchThreadList(limit=20) num = (num - 20) / 20 for i in range(num): offset = 20 * (i + 1)
import time from datetime import datetime from fbchat import Client from fbchat.models import * def sendit(): current_time = datetime.now().strftime("%-I:%M") message = 'Yo ' + person + ' it is ' \ + str(current_time) + \ " and I'm thinking of you ❤️ " client.send(Message(text=message), thread_id=thread.uid, thread_type=ThreadType.USER) print('Please enter Facebook creds to continue \n') client = Client(input('Email: '), input('Password:'******'The UID of ' + person + ' is ' + str(thread.uid)) firstmessagetime = "09:00" secondmessagetime = "16:20" schedule.every().day.at(firstmessagetime).do(sendit) schedule.every().day.at(secondmessagetime).do(sendit) while True: schedule.run_pending() time.sleep(10)
threads = client.fetchThreadList() # Fetches the next 10 threads threads += client.fetchThreadList(offset=20, limit=10) print("Threads: {}".format(threads)) # Gets the last 10 messages sent to the thread messages = client.fetchThreadMessages(thread_id=thread_id, limit=10) # Since the message come in reversed order, reverse them messages.reverse() # Prints the content of all the messages for message in messages: print(message.text) # If we have a thread id, we can use `fetchThreadInfo` to fetch a `Thread` object thread = client.fetchThreadInfo(thread_id)[thread_id] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # `searchForThreads` searches works like `searchForUsers`, but gives us a list of threads instead thread = client.searchForThreads('Android')[0] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) # Here should be an example of `getUnread` client.logout()
def cli(): #state variable enables the user to keep running the cli app runCLI = True try: # get login information from user and log in to the client loginInfo = login() email = loginInfo['email'] pw = loginInfo['password'] client = Client(email, pw) except fbchat.FBchatException as e: #the exception isn't here print('There was an exception: %e' % (e)) while runCLI: #ask the user for actions they want to take action = actions() #reading messages if action.get('actionsOnStart') == 'Read messages': toRead = getMessages() #reading messages from favorite users if toRead.get('messagesToRead') == 'My favorites': if os.path.exists('favorites.csv'): #open the file if it exists with open('favorites.csv', 'rb') as favoritesFile: favorites = pickle.load(favoritesFile) #if file exists but favorites list is empty, let the user know if favorites == []: print('Your favorites list is empty.') #otherwise get the conversations and print the conversations else: print( '----------------------------------------------------------' ) print('Fetching your favorite conversations...') print( '----------------------------------------------------------' ) for thread in favorites: print('Your conversation with ' + thread.name + ': ') readMessage(thread, client) # if no file exists, let the user know there are no favorites else: print('Your favorites list is empty.') #reading messages from five most recent conversations elif toRead.get('messagesToRead') == 'Recent conversations': #fetch conversations threads = client.fetchThreadList(limit=5) print( '----------------------------------------------------------' ) print('Fetching your five most recent conversations...') print( '----------------------------------------------------------' ) #print messages for thread in threads: print('Your conversation with ' + thread.name + ': ') readMessage(thread, client) #reading messages from a specific user or group elif toRead.get('messagesToRead') == 'Someone else': #get necessary information user = getUser() #search function is different for users and groups if user.get('userOrGroup') == 'User': userToRead = client.searchForUsers( str(user.get('userToRead'))) elif user.get('userOrGroup') == 'Group': userToRead = client.searchForGroups( str(user.get('userToRead'))) #print messages print( '----------------------------------------------------------' ) print('Your conversation with ' + userToRead[0].name + ': ') readMessage(userToRead[0], client) #sending a message elif action.get('actionsOnStart') == 'Send a message': #ask for information about the message messageInfo = getMessageInfo() #send message try: response = sendMessage(messageInfo, client) print("Your message was sent!") except Exception as exception: #raise exception if message cannot be sent raise Exception('We have an error: %s' % (exception)) #adding to favorites elif action.get('actionsOnStart') == 'Add to favorites': #if file exists open it and load contents to list if os.path.exists('favorites.csv'): with open('favorites.csv', 'rb') as favoritesFile: favorites = pickle.load(favoritesFile) #otherwise file doesn't exist, initialize empty list else: favorites = [] #get information of user/group to be added and search for said user/group toAdd = addFavorite() user = client.searchForThreads(str(toAdd.get('toAdd'))) #append the new favorite if not already in favorites list if user[0] not in favorites: favorites.append(user[0]) #write the entire favorites list to the file (as user objects) with open('favorites.csv', 'wb') as favoritesFile: pickle.dump(favorites, favoritesFile) #let the user know favorite has been added print(user[0].name + ' has been added to your favorites list!') #deleting from favorites elif action.get('actionsOnStart') == 'Delete from favorites': #if file exists, open it and load contents to list if os.path.exists('favorites.csv'): with open('favorites.csv', 'rb') as favoritesFile: favorites = pickle.load(favoritesFile) #if favorites is not empty, get information of user/group to be deleted if favorites != []: toDelete = deleteFavorite(favorites) userToDelete = str(toDelete.get('toDelete')) #remove user if in existing favorites list for user in favorites: if userToDelete == user.name: favorites.remove(user) print(userToDelete + ' was deleted from your favorites list.') #now write the modified favorites list to file with open('favorites.csv', 'wb') as favoritesFile: pickle.dump(favorites, favoritesFile) # if favorites list is empty let user know else: print('There is no existing favorites list.') #if there is no favorites file let user know else: print('There is no existing favorites list.') #ask the user if they want to terminate the session endSession = terminate().get('terminate') #modify state variable if necessary if endSession == 'Yes': runCLI = False #logout at the end, let the user know client.logout() print('You have been logged out. See you soon!')