Ejemplo n.º 1
0
async def target_info(target):
    page, _ = await browser_config.configure_browser_and_load_whatsapp()

    if target is not None:
        try:
            await target_search.search_and_select_target(page, target)
        except Exception as e:
            print(e)
            await page.reload()
            await target_search.search_and_select_target_without_new_chat_button(
                page, target)
    else:
        await target_select.manual_select_target(page)

    browser_config.minimize()
    """
    # to find location by ip address
    print('Get you ipinfo token from https://ipinfo.io/account')
    ip_address = '*'
    token = str(input("Enter your ipinfo token: "))
    ip_string = 'curl ipinfo.io/'+ip_address+'?token='+token+''
    os.system(ip_string)
    """
    __logger.info("Writing target's information")
    scanNumber(target_contact_number.phone_number)
Ejemplo n.º 2
0
async def get_news(target):
    def fetch_news(country_code):
        headlines = newsapi.get_top_headlines(country=country_code,
                                              language='en')
        url = headlines['articles'][0]['url']
        title = headlines['articles'][0]['title']
        return title, url

    page, _ = await browser_config.configure_browser_and_load_whatsapp()
    if target is not None:
        try:
            await target_search.search_and_select_target(page, target)
        except Exception as e:
            print(e)
            await target_search.search_and_select_target_without_new_chat_button(
                page, target)
    else:
        await target_select.manual_select_target(page)

    browser_config.minimize()
    country = input("Enter your country code (ex: us or in): ")
    while True:
        try:
            news, source = fetch_news(country)
            news_ = f"*{news}* \n Full News :  {source}"
            await io.send_message(page, news_)
        except Exception as e:
            print("Unable to get the news", e)
        time.sleep(120)  # Sends news in every 2 min
Ejemplo n.º 3
0
async def tracker(target):
    '''
    This function checks the online and offline status of the target person.
    '''
    page, _ = await browser_config.configure_browser_and_load_whatsapp() # open bot browser and load whatsapp web website
    if target is not None: # checks if target is not none then it search for the target and select it
        try:
            target_name = await target_search.search_and_select_target(page, target, hide_groups=True)
        except Exception as e:
            print(e)
            await page.reload()
            target_name = await target_search.search_and_select_target_without_new_chat_button(page, target, hide_groups=True)
    else: # if target is none then it allow user to select target manually from browser
        target_name = await target_select.manual_select_target(page, hide_groups=True)

    browser_config.minimize()
    # opens status file of the target person
    status_file: str = open(tracking_folder_path / f'status_{target_name}.txt', 'w').close()
    status_file: str = open(tracking_folder_path / f'status_{target_name}.txt', 'a')

    # default assignes
    is_sound_enabled: bool = True
    last_status: str = 'offline'
    try:
        print(f'Tracking: {target_name}')
        __logger.info("Tracking target")
        status_file.write(f'Tracking: {target_name}\n')
        while True:
            status: str = await target_data.get_last_seen_from_focused_target(page) # checks last seen
            if status == 'online': # if last seen is online then shows online
                is_online: bool = True
            else: # if nothing is there so shows offline
                is_online: bool = False
                status: str = 'offline'
            # play a notification sound on online
            if last_status != is_online:
                if is_online:
                    try:
                        if is_sound_enabled:
                            playsound('plucky.wav')
                    except Exception as e:
                        print("Error: Couldn't play the sound.")
                        is_sound_enabled: bool = False
                print(
                    f'{datetime.now().strftime("%d/%m/%Y, %H:%M:%S")}' + f' - Status: {status}'
                )
                status_file.write(
                    f'{datetime.now().strftime("%d/%m/%Y, %H:%M:%S")}' + f' - Status: {status}\n')
            last_status: str = is_online
            time.sleep(0.5)
    except KeyboardInterrupt:
        __logger.error("User Pressed Ctrl+C")
    finally:
        # save the status and close the file
        status_file.close()
        print(f'\nStatus file saved in: {str(tracking_folder_path/"status_")}{target_name}.txt')
Ejemplo n.º 4
0
async def message_service():
    page, _ = await browser_config.configure_browser_and_load_whatsapp()
    browser_config.minimize()
    __logger.info("Message Service On.")
    print("Message Service is ON, press CTRL+C to stop.")
    print(
        "Listening for messages in file 'messages.json' inside user/wplay/messagesJSON folder."
    )
    # Initialize a instance of MessageStack

    message_stack = MessageStack()
    # Move all messages from open_messages.json to messages.json when the program starts
    message_stack.move_all_messages(helpers.open_messages_json_path,
                                    helpers.messages_json_path)

    while True:
        if verify_internet.internet_avalaible():
            try:
                # Try to get the message
                current_msg = next(message_stack.get_message())

                # Move message from messages.json to open_messages.json
                message_stack.move_message(helpers.messages_json_path,
                                           helpers.open_messages_json_path,
                                           current_msg['uuid'])

                try:
                    if await search_target_by_number(page,
                                                     current_msg['number']):
                        await io.send_message(page, current_msg['message'])
                    message_stack.remove_message(
                        current_msg['uuid'], helpers.open_messages_json_path)
                except ValueError:
                    __logger.debug("Wrong JSON Formatting. Message Deleted.")
                    message_stack.remove_message(
                        current_msg['uuid'], helpers.open_messages_json_path)
                except Exception as e:
                    # If any error occurs that is not because of wrong data,
                    # the message will be moved back to messages.json
                    __logger.error(
                        f'Error handling and sending the message: {str(e)}')
                    MessageStack().move_message(
                        helpers.open_messages_json_path,
                        helpers.messages_json_path, current_msg['uuid'])
            except (StopIteration, json.JSONDecodeError):
                # if there are no messages to catch we will have this 'Warning', will try again after a time
                time.sleep(1)
        else:
            __logger.debug(
                'Internet is not available, trying again after 15 seconds.')
            time.sleep(15)
        # Move messages from open_messages.json to messages.json that wasn't sended.
        message_stack.move_all_messages(helpers.open_messages_json_path,
                                        helpers.messages_json_path)
Ejemplo n.º 5
0
async def message_blast(target: str):
    page, _ = await browser_config.configure_browser_and_load_whatsapp()
    if target is not None:
        await target_search.search_and_select_target_all_ways(page, target)
    else:
        await target_select.manual_select_target(page)

    browser_config.minimize()
    message: List[str] = io.ask_user_for_message_breakline_mode()
    number_of_messages: int = int(input("Enter the number of messages to blast: "))
    __logger.debug("Blasting messages")
    for _ in range(number_of_messages):
        await io.send_message(page, message)
Ejemplo n.º 6
0
async def chat(target):
    initial_minimize = True
    __logger.info("Chatting with target")
    page, _ = await browser_config.configure_browser_and_load_whatsapp()

    if target is not None:
        try:
            await target_search.search_and_select_target(page, target)
        except Exception as e:
            print(e)
            await page.reload()
            await target_search.search_and_select_target_without_new_chat_button(
                page, target)
    else:
        target = await target_select.manual_select_target(page)

    print("\033[91m {}\033[00m".format(
        "\nType '...' in a new line or alone in the message to change target person.\nType '#_FILE' to send Image/Video/Documentd etc.\n"
    ))

    while True:
        if (initial_minimize):
            browser_config.minimize()
            initial_minimize = False

        await getMessages(page, target)
        message: list[str] = io.ask_user_for_message_breakline_mode()

        if '...' in message:
            message.remove('...')
            await io.send_message(page, message)
            target = input("\n\nNew Target Name: ")
            if target is not None:
                await target_search.search_and_select_target(page, target)
            else:
                await target_select.manual_select_target(page)
            message = io.ask_user_for_message_breakline_mode()

        # File Share:
        if '#_FILE' in message:
            message.remove('#_FILE')
            await io.send_file(page)
        await getMessages(page, target)
        await io.send_message(page, message)
Ejemplo n.º 7
0
async def message_timer(target):
    page, _ = await browser_config.configure_browser_and_load_whatsapp()
    if target is not None:
        try:
            await target_search.search_and_select_target(page, target)
        except Exception as e:
            print(e)
            await page.reload()
            await target_search.search_and_select_target_without_new_chat_button(
                page, target)
    else:
        await target_select.manual_select_target(page)

    browser_config.minimize()
    # Region INPUTS
    __logger.info("Input message information for message timer")
    message_type_numbers: int = int(
        input("How many types of messages will you send? "))
    messages: list[str] = list()
    for _ in range(message_type_numbers):
        messages.append(io.ask_user_for_message_breakline_mode())
    number_of_messages: int = int(
        input("Enter the number of messages to send: "))
    minimumTimeInterval: int = int(
        input("Enter minimum interval number in seconds: "))
    maximumTimeInterval: int = int(
        input("Enter maximum interval number in seconds: "))
    # Endregion

    random.seed()
    for _ in range(number_of_messages):
        if not messages:
            break
        await io.send_message(
            page, messages[random.randrange(0, message_type_numbers)])
        if minimumTimeInterval != maximumTimeInterval:
            time.sleep(
                random.randrange(minimumTimeInterval, maximumTimeInterval))
        else:
            time.sleep(minimumTimeInterval)
Ejemplo n.º 8
0
async def schedule_message(target):
    page, _ = await browser_config.configure_browser_and_load_whatsapp()
    if target is not None:
        await target_search.search_and_select_target(page, target)
    else:
        await target_select.manual_select_target(page)

    browser_config.minimize()
    time_ = input("Enter the schedule time in HH:MM:SS format-> ")
    hour, minute, second = time_.split(':')
    current_time = datetime.now()
    delta_hour: int = int(hour) - current_time.hour
    delta_min: int = int(minute) - current_time.minute
    delta_second: int = int(second) - current_time.second
    total_seconds: int = delta_hour * 3600 + delta_min * 60 + delta_second
    if total_seconds < 0:
        print("Current time is ahead of the scheduled time")
        sys.exit()
    message: list[str] = io.ask_user_for_message_breakline_mode()
    print("Your message is scheduled at : ", time_)
    time.sleep(total_seconds)
    await io.send_message(page, message)
Ejemplo n.º 9
0
async def download_media(target):
    page, browser = await browser_config.configure_browser_and_load_whatsapp()

    if target is not None:
        try:
            await target_search.search_and_select_target(page, target)
        except Exception as e:
            print(e)
            await page.reload()
            await target_search.search_and_select_target_without_new_chat_button(
                    page,
                    target
                    )
    else:
        await target_select.manual_select_target(page)
    browser_config.minimize()
    count = int(input("Count of media you want to download: "))

    # Click on the photo element of the target
    await page.waitForSelector(whatsapp_selectors_dict['target_name_selector'], visible=True)
    await page.evaluate(f'''document.querySelector('{whatsapp_selectors_dict['target_name_selector']}').click()''')

    time.sleep(1)

    # Click on the `Media, Link and Docs` text
    await page.waitForSelector(whatsapp_selectors_dict['media_text'])
    await page.click(whatsapp_selectors_dict['media_text'])

    # Click on the most recent media element
    while True:
        try:
            await page.evaluate(f'''document.querySelector('{whatsapp_selectors_dict['media_images']}').click()''')
            break
        except Exception as e:
            print("", end='')

    media_arr = {'img': [], 'vid': []}

    # Currently downloads the last 50 medias
    for _ in range(count):
        try:
            try:
                # If media is an image
                countTry = 0 # Threshold of how many times to try looking for media
                while True:
                    if countTry > 500:
                        await page.waitForSelector(whatsapp_selectors_dict['left_arrow_button'])

                    img = await page.evaluate(f'''() => [...document.querySelectorAll('{whatsapp_selectors_dict['media_url_img']}')]
                                                        .map(element => element.src)''')
                    if img and len(img) == 2:
                        img = img[-1]
                        if img not in media_arr:
                            media_arr['img'].append(img)
                        break
                    countTry += 1
                    time.sleep(0.3)
            except Exception as e:
                # If media is a video or gif
                countTry = 0
                while True:
                    vid = await page.evaluate(f'''() => [...document.querySelectorAll('{whatsapp_selectors_dict['media_url_vid']}')]
                                                        .map(element => element.src)''')
                    if vid:
                        vid = vid[-1]
                        media_arr['vid'].append(vid)
                        break

            # Go to next media element
            await page.waitForSelector(whatsapp_selectors_dict['left_arrow_button'])
            await page.evaluate(f'''document.querySelector('{whatsapp_selectors_dict['left_arrow_button']}').click()''')
            time.sleep(0.5)

        except Exception as e:
            print(e)

    count = 0
    newPage = await browser.newPage()
    # Downloading media
    for image in media_arr['img']:
        try:
            count += 1
            print(image)
            viewSource = await newPage.goto(image)
            f = open(media_path / f'{count}.jpg', 'wb')
            f.write(await viewSource.buffer())
            f.close()
        except Exception as e:
            print("Error saving image", e)

    for video in media_arr['vid']:
        try:
            count += 1
            viewSource = await newPage.goto(video)
            f = open(media_path / f'{count}.mp4', 'wb')
            f.write(await viewSource.buffer())
            f.close()
        except Exception as e:
            print("Error saving video", e)

    print("Saved the media to the 'media' dir")
    time.sleep(10)