def download_pictures(user, password, thread_id, output_folder): downloaded = 0 if not isdir(output_folder): mkdir(output_folder) client = Client(user, password) images = client.fetchThreadImages(thread_id) for im in images: if not type(im) == ImageAttachment: continue if (im.original_extension) == 'gif': continue img_filename = im.uid + ".jpg" output_filename = join(output_folder, img_filename) if (isFileExist(img_filename)): print("File %s already downloaded" % img_filename) continue url = client.fetchImageUrl(im.uid) data = http.request("GET", url=url, preload_content=False) data = data.read() downloaded += 1 print("Downloading %s" % output_filename) with open(output_filename, "wb") as f: f.write(data) client.send( Message(text="Synchronisation du cloud fini, nb photos telecharges: " + str(downloaded)), thread_id=client.uid, thread_type=ThreadType.USER) client.send( Message(text="Synchronisation du cloud fini, nb photos telecharges: " + str(downloaded)), thread_id=thread_id, thread_type=ThreadType.USER) client.logout()
thread_info = client.fetchThreadInfo(threads[i].uid)[threads[i].uid] print('[{}] {}'.format(i, thread_info.name)) selected_thread = int(input('Select thread: ')) if not selected_thread > thread_limit - 1: thread_uid = client.fetchThreadInfo( threads[selected_thread].uid)[threads[selected_thread].uid].uid print('Selected thread uid: {}'.format(thread_uid)) thread_dir = os.path.join(os.path.dirname(__file__), thread_uid) if not os.path.isdir(thread_dir): os.mkdir(thread_dir) attachments = client.fetchThreadImages(thread_uid) files_count = 0 for attachment in attachments: try: url = client.fetchImageUrl(attachment.uid) except FBchatException as e: print(e) continue if type(attachment) == ImageAttachment: wget.download(url, thread_dir + '/' + attachment.uid + '.png') elif type(attachment) == VideoAttachment: wget.download(url, thread_dir + '/' + attachment.uid + '.mp4') files_count += 1
# 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 image url for 20 last images from thread. images = client.fetchThreadImages("<thread id>") for image in islice(image, 20): print(image.large_preview_url)