diff --git a/wplay/about_changer.py b/wplay/about_changer.py index 68dc2750..ab8df28f 100644 --- a/wplay/about_changer.py +++ b/wplay/about_changer.py @@ -17,6 +17,7 @@ async def about_changer(): page, _ = await browser_config.configure_browser_and_load_whatsapp() + browser_config.minimize_delay() query: str = str(input("What's the news theme? : ")) await page.waitForSelector(whatsapp_selectors_dict['profile_photo_element'], visible=True) diff --git a/wplay/broadcast_message.py b/wplay/broadcast_message.py index a8521008..8b9c69b6 100644 --- a/wplay/broadcast_message.py +++ b/wplay/broadcast_message.py @@ -22,6 +22,7 @@ class InvalidNumber(Exception): def ProcessNumbers(): __logger.info("Processing numbers.") + browser_config.minimize_delay() print("Choose a text file containing full numbers with country code, one number per line.") Tk().withdraw() filename = askopenfile( diff --git a/wplay/download_media.py b/wplay/download_media.py index f2d5e81d..85879faf 100644 --- a/wplay/download_media.py +++ b/wplay/download_media.py @@ -31,7 +31,7 @@ async def download_media(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 diff --git a/wplay/get_media.py b/wplay/get_media.py index 6ab4106f..b2467a0c 100644 --- a/wplay/get_media.py +++ b/wplay/get_media.py @@ -15,6 +15,7 @@ async def get_profile_photos(): page, _ = await browser_config.configure_browser_and_load_whatsapp() + browser_config.minimize_delay() total_contacts = int(input("Please provide total whatsapp contacts: ")) loop = round(total_contacts/7) images_list = [] diff --git a/wplay/get_news.py b/wplay/get_news.py index f044a389..6c9c0868 100644 --- a/wplay/get_news.py +++ b/wplay/get_news.py @@ -38,6 +38,7 @@ def fetch_news(country_code): else: await target_select.manual_select_target(page) + browser_config.minimize() country = input("Enter your country code (ex: us or in): ") while True: try: diff --git a/wplay/message_blast.py b/wplay/message_blast.py index e9b1bef6..4d1b182c 100644 --- a/wplay/message_blast.py +++ b/wplay/message_blast.py @@ -22,6 +22,8 @@ async def message_blast(target: str): 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") diff --git a/wplay/message_service.py b/wplay/message_service.py index 104d96bc..8259e334 100644 --- a/wplay/message_service.py +++ b/wplay/message_service.py @@ -44,10 +44,12 @@ 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) @@ -79,6 +81,5 @@ async def message_service(): 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) diff --git a/wplay/message_timer.py b/wplay/message_timer.py index dc510d1e..a7e312b0 100644 --- a/wplay/message_timer.py +++ b/wplay/message_timer.py @@ -28,6 +28,8 @@ async def message_timer(target): 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? ")) diff --git a/wplay/online_tracker.py b/wplay/online_tracker.py index 089348ba..6a8f96ff 100644 --- a/wplay/online_tracker.py +++ b/wplay/online_tracker.py @@ -31,6 +31,7 @@ async def tracker(target): 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') diff --git a/wplay/schedule_message.py b/wplay/schedule_message.py index 1c208207..4c38a4f6 100644 --- a/wplay/schedule_message.py +++ b/wplay/schedule_message.py @@ -23,6 +23,8 @@ async def schedule_message(target): 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() diff --git a/wplay/target_info.py b/wplay/target_info.py index ec8d186e..ce96a94c 100644 --- a/wplay/target_info.py +++ b/wplay/target_info.py @@ -101,6 +101,8 @@ async def target_info(target): 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') diff --git a/wplay/terminal_chat.py b/wplay/terminal_chat.py index abf0a4c9..848c9098 100644 --- a/wplay/terminal_chat.py +++ b/wplay/terminal_chat.py @@ -18,6 +18,7 @@ async def chat(target): + initial_minimize = True __logger.info("Chatting with target") page, _ = await browser_config.configure_browser_and_load_whatsapp() @@ -34,6 +35,10 @@ async def chat(target): 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() @@ -73,15 +78,15 @@ async def getMessages(pg, tg): print(e) lastMessage = "" lastOutgoingMessage = '' - if tg.lower() in last_message_sender.lower() and lastOutgoingMessage!=lastMessage: + if tg.lower() in last_message_sender.lower() and lastOutgoingMessage != lastMessage: print(Fore.GREEN + f"{tg}-", end="") print(lastMessage, end="") if '/image' in lastMessage: - bot_msg=await chatbot.Bot(last_Message = lastMessage) + bot_msg = await chatbot.Bot(last_Message = lastMessage) await io.send_message(pg, bot_msg) await io.send_file(pg) elif lastMessage[0] == '/': - bot_msg=await chatbot.Bot(last_Message = lastMessage) + bot_msg = await chatbot.Bot(last_Message = lastMessage) await io.send_message(pg, bot_msg) print(Style.RESET_ALL) lastOutgoingMessage = lastMessage diff --git a/wplay/utils/browser_config.py b/wplay/utils/browser_config.py index c91c8109..83b9bb01 100644 --- a/wplay/utils/browser_config.py +++ b/wplay/utils/browser_config.py @@ -28,6 +28,8 @@ async def my_script(target): # region IMPORTS from typing import Any, List from pathlib import Path +import win32gui, win32con +import time import websockets.client from pyppeteer import launch, connection, launcher @@ -137,6 +139,21 @@ async def __set_view_port(page: Page): await page.setViewport({'width': 1280, 'height': 800}) # endregion +def minimize_delay(): + #Waiting time for Login + time.sleep(8) + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) +#endregion + +def minimize(): + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) +#endregion # region CODE THAT MIGHT BE USEFUL SOMEDAY '''