Last active
September 6, 2019 14:01
-
-
Save hclivess/ed4dfada5472131adfd1b70167888fbf to your computer and use it in GitHub Desktop.
fb_message_sender.py
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
from fbchat import Client | |
from fbchat.models import * | |
import time | |
import json | |
import random | |
counter = 0 | |
with open("secret.json") as file: | |
parsed = json.loads(file.read()) | |
username = parsed['username'] | |
password = parsed['password'] | |
text = parsed['text'] | |
def login(): | |
client = Client(username, password) | |
return client | |
# Fetches a list of all users you're currently chatting with, as `User` objects | |
client = login() | |
users = client.fetchAllUsers() | |
print(f"users' IDs: {[user.uid for user in users]}") | |
print(f"users' names: {[user.name for user in users]}") | |
print(f"ready to send mass message {text}") | |
for user in users: | |
with open("sent.json","r") as file: | |
parsed = json.loads(file.read()) | |
try: | |
while True: | |
if user.uid not in parsed: | |
client = login() | |
print(f"sending message to {user.name}") | |
client.send(Message(text=text), thread_id=user.uid, thread_type=ThreadType.USER) | |
counter += 1 | |
print(f"{counter} messages sent in total") | |
with open("sent.json", "w") as file: | |
parsed[user.uid]=user.name | |
file.write(json.dumps(parsed)) | |
delay = random.randint(1, 360) | |
print(f"sleeping for {delay} seconds...") | |
time.sleep(delay) | |
else: | |
print(f"skipping {user.uid}, {user.name}, message already sent") | |
break | |
except Exception as e: | |
print(e) | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment