From b339f6c7d97ccd1c5a5154df026253706163675d Mon Sep 17 00:00:00 2001 From: Soumya Shaw <37841510+soumyashaw@users.noreply.github.com> Date: Sun, 17 May 2020 13:21:46 +0530 Subject: [PATCH 01/12] Minimizing Browser Window --- wplay/terminal_chat.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wplay/terminal_chat.py b/wplay/terminal_chat.py index 510e90e5..4ad35b2d 100644 --- a/wplay/terminal_chat.py +++ b/wplay/terminal_chat.py @@ -1,5 +1,6 @@ # region IMPORTS from pathlib import Path +import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -18,6 +19,7 @@ async def chat(target): + initial_minimize = True __logger.info("Chatting with target") page, _ = await browser_config.configure_browser_and_load_whatsapp() @@ -34,6 +36,13 @@ 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: + #Minimizing the Window after Target Select + if (initial_minimize==True): + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + initial_minimize = False + await getMessages(page, target) message: list[str] = io.ask_user_for_message_breakline_mode() From ccc24dc6ce1cff0dee0e8029472e197b96d3c82e Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Tue, 19 May 2020 00:16:08 +0530 Subject: [PATCH 02/12] Create get_target_media.py --- wplay/get_target_media.py | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 wplay/get_target_media.py diff --git a/wplay/get_target_media.py b/wplay/get_target_media.py new file mode 100644 index 00000000..6ab4106f --- /dev/null +++ b/wplay/get_target_media.py @@ -0,0 +1,47 @@ +# region Imports +import time +from pathlib import Path + +from wplay.utils import browser_config +from wplay.utils.Logger import Logger +from wplay.utils.helpers import profile_photos_path +# endregion + + +# region LOGGER +__logger = Logger(Path(__file__).name) +# endregion + + +async def get_profile_photos(): + page, _ = await browser_config.configure_browser_and_load_whatsapp() + total_contacts = int(input("Please provide total whatsapp contacts: ")) + loop = round(total_contacts/7) + images_list = [] + + await page.waitForSelector('#pane-side > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div > div > img') + + for c in range(loop): + for i in range(1, 18): + selector = f"#pane-side > div:nth-child(1) > div > div > div:nth-child({i}) > div > div > div > div > img" + try: + await page.waitForSelector(selector, timeout=2000) + image_url = await page.evaluate(f'document.querySelector("{selector}").getAttribute("src")') + print(f"{c}:{i}-{image_url}") + if image_url not in images_list: + images_list.append(image_url) + except Exception as e: + print("No profile image found") + await page.evaluate("document.querySelector('#pane-side').scrollBy(0, 500)") + + for count in range(len(images_list)): + try: + viewSource = await page.goto(images_list[count]) + f = open(profile_photos_path / f'{count}.jpg', 'wb') + f.write(await viewSource.buffer()) + f.close() + except Exception as e: + print("Error saving image") + + print("Saved all the images to media_folder.") + time.sleep(5) From 1fa304b711ac375af07732f2640250daddaa07a9 Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Tue, 19 May 2020 22:51:19 +0530 Subject: [PATCH 03/12] Delete get_target_media.py --- wplay/get_target_media.py | 47 --------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 wplay/get_target_media.py diff --git a/wplay/get_target_media.py b/wplay/get_target_media.py deleted file mode 100644 index 6ab4106f..00000000 --- a/wplay/get_target_media.py +++ /dev/null @@ -1,47 +0,0 @@ -# region Imports -import time -from pathlib import Path - -from wplay.utils import browser_config -from wplay.utils.Logger import Logger -from wplay.utils.helpers import profile_photos_path -# endregion - - -# region LOGGER -__logger = Logger(Path(__file__).name) -# endregion - - -async def get_profile_photos(): - page, _ = await browser_config.configure_browser_and_load_whatsapp() - total_contacts = int(input("Please provide total whatsapp contacts: ")) - loop = round(total_contacts/7) - images_list = [] - - await page.waitForSelector('#pane-side > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div > div > img') - - for c in range(loop): - for i in range(1, 18): - selector = f"#pane-side > div:nth-child(1) > div > div > div:nth-child({i}) > div > div > div > div > img" - try: - await page.waitForSelector(selector, timeout=2000) - image_url = await page.evaluate(f'document.querySelector("{selector}").getAttribute("src")') - print(f"{c}:{i}-{image_url}") - if image_url not in images_list: - images_list.append(image_url) - except Exception as e: - print("No profile image found") - await page.evaluate("document.querySelector('#pane-side').scrollBy(0, 500)") - - for count in range(len(images_list)): - try: - viewSource = await page.goto(images_list[count]) - f = open(profile_photos_path / f'{count}.jpg', 'wb') - f.write(await viewSource.buffer()) - f.close() - except Exception as e: - print("Error saving image") - - print("Saved all the images to media_folder.") - time.sleep(5) From 85b1084bb3f138439358aed97c3b4266abfe859f Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Wed, 20 May 2020 18:04:14 +0530 Subject: [PATCH 04/12] Update about_changer.py --- wplay/about_changer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wplay/about_changer.py b/wplay/about_changer.py index 68dc2750..d6235669 100644 --- a/wplay/about_changer.py +++ b/wplay/about_changer.py @@ -2,6 +2,7 @@ import time import os import sys +import win32gui, win32con from newsapi.newsapi_client import NewsApiClient import requests @@ -17,6 +18,15 @@ async def about_changer(): page, _ = await browser_config.configure_browser_and_load_whatsapp() + + #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) + query: str = str(input("What's the news theme? : ")) await page.waitForSelector(whatsapp_selectors_dict['profile_photo_element'], visible=True) From 25e80b04f6a535e56f00dc14a71756200b708338 Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Wed, 20 May 2020 18:06:44 +0530 Subject: [PATCH 05/12] Added minimize window feature --- wplay/broadcast_message.py | 11 +++++++++++ wplay/download_media.py | 6 ++++++ wplay/get_media.py | 10 ++++++++++ wplay/get_news.py | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/wplay/broadcast_message.py b/wplay/broadcast_message.py index a8521008..cc82916b 100644 --- a/wplay/broadcast_message.py +++ b/wplay/broadcast_message.py @@ -2,6 +2,8 @@ from tkinter import Tk from tkinter.filedialog import askopenfile from pathlib import Path +import time +import win32gui, win32con from wplay.utils import browser_config from wplay.utils.target_search import search_target_by_number @@ -22,6 +24,15 @@ class InvalidNumber(Exception): def ProcessNumbers(): __logger.info("Processing numbers.") + + #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) + 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..3dbec701 100644 --- a/wplay/download_media.py +++ b/wplay/download_media.py @@ -1,5 +1,6 @@ # region Imports from pathlib import Path +import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -32,6 +33,11 @@ async def download_media(target): else: await target_select.manual_select_target(page) + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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..bc43a518 100644 --- a/wplay/get_media.py +++ b/wplay/get_media.py @@ -1,6 +1,7 @@ # region Imports import time from pathlib import Path +import win32gui, win32con from wplay.utils import browser_config from wplay.utils.Logger import Logger @@ -15,6 +16,15 @@ async def get_profile_photos(): page, _ = await browser_config.configure_browser_and_load_whatsapp() + + #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) + 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 ad54393f..14afba83 100644 --- a/wplay/get_news.py +++ b/wplay/get_news.py @@ -2,6 +2,7 @@ from pathlib import Path import time import os +import win32gui, win32con from dotenv import load_dotenv from newsapi.newsapi_client import NewsApiClient @@ -40,6 +41,11 @@ def fetch_news(country_code): else: await target_select.manual_select_target(page) + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + country = input("Enter your country code (ex: us or in): ") while True: try: From e04226bb273ef44d3635f838a34babfb1d751a6d Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Wed, 20 May 2020 18:08:27 +0530 Subject: [PATCH 06/12] Browser minimize --- wplay/get_target_media.py | 47 +++++++++++++++++++++++++++++++++++++++ wplay/message_blast.py | 7 ++++++ wplay/message_service.py | 10 ++++++++- wplay/message_timer.py | 7 ++++++ wplay/online_tracker.py | 6 +++++ wplay/schedule_message.py | 7 ++++++ wplay/target_info.py | 7 ++++++ 7 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 wplay/get_target_media.py diff --git a/wplay/get_target_media.py b/wplay/get_target_media.py new file mode 100644 index 00000000..d6e142e6 --- /dev/null +++ b/wplay/get_target_media.py @@ -0,0 +1,47 @@ +# region Imports +import time +from pathlib import Path + +from wplay.utils import browser_config +from wplay.utils.Logger import Logger +from wplay.utils.helpers import profile_photos_path +# endregion + + +# region LOGGER +__logger = Logger(Path(__file__).name) +# endregion + +#-----------------------------------------------chnage 1: function name----------------------------------- +async def get_target_profile_photos(): + page, _ = await browser_config.configure_browser_and_load_whatsapp() + total_contacts = int(input("Please provide total whatsapp contacts: ")) + loop = round(total_contacts/7) + images_list = [] + + await page.waitForSelector('#pane-side > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div > div > img') + + for c in range(loop): + for i in range(1, 18): + selector = f"#pane-side > div:nth-child(1) > div > div > div:nth-child({i}) > div > div > div > div > img" + try: + await page.waitForSelector(selector, timeout=2000) + image_url = await page.evaluate(f'document.querySelector("{selector}").getAttribute("src")') + print(f"{c}:{i}-{image_url}") + if image_url not in images_list: + images_list.append(image_url) + except Exception as e: + print("No profile image found") + await page.evaluate("document.querySelector('#pane-side').scrollBy(0, 500)") + + for count in range(len(images_list)): + try: + viewSource = await page.goto(images_list[count]) + f = open(profile_photos_path / f'{count}.jpg', 'wb') + f.write(await viewSource.buffer()) + f.close() + except Exception as e: + print("Error saving image") + + print("Saved all the images to media_folder.") + time.sleep(5) diff --git a/wplay/message_blast.py b/wplay/message_blast.py index e9b1bef6..d1590017 100644 --- a/wplay/message_blast.py +++ b/wplay/message_blast.py @@ -1,6 +1,7 @@ # region IMPORTS from pathlib import Path from typing import List +import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -22,6 +23,12 @@ 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) + + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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..364d966d 100644 --- a/wplay/message_service.py +++ b/wplay/message_service.py @@ -3,6 +3,7 @@ import threading import time import json +import win32gui, win32con from wplay.utils import browser_config from wplay.utils.target_search import search_target_by_number @@ -44,10 +45,17 @@ async def message_service(): page, _ = await browser_config.configure_browser_and_load_whatsapp() + + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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 +87,6 @@ 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..28cb5290 100644 --- a/wplay/message_timer.py +++ b/wplay/message_timer.py @@ -1,6 +1,7 @@ # region IMPORTS import time import random +import win32gui, win32con from pathlib import Path from wplay.utils import browser_config @@ -28,6 +29,12 @@ 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) + + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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..e842bd5e 100644 --- a/wplay/online_tracker.py +++ b/wplay/online_tracker.py @@ -1,4 +1,5 @@ import time +import win32gui, win32con from pathlib import Path from datetime import datetime from playsound import playsound @@ -31,6 +32,11 @@ 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) + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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..aa48f016 100644 --- a/wplay/schedule_message.py +++ b/wplay/schedule_message.py @@ -3,6 +3,7 @@ from pathlib import Path import time import sys +import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -23,6 +24,12 @@ async def schedule_message(target): await target_search.search_and_select_target(page, target) else: await target_select.manual_select_target(page) + + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_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..7ef95554 100644 --- a/wplay/target_info.py +++ b/wplay/target_info.py @@ -8,6 +8,7 @@ from phonenumbers import timezone import re import sys +import win32gui, win32con from pathlib import Path from wplay.utils.Logger import Logger # end IMPORTS @@ -101,6 +102,12 @@ 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) + + #Minimizing the Window after Target Select + print("Browser Minimized") + Minimize = win32gui.GetForegroundWindow() + win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + """ # to find location by ip address print('Get you ipinfo token from https://ipinfo.io/account') From ff02104ac329a1105256c82b269e990006815de3 Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Fri, 22 May 2020 00:01:34 +0530 Subject: [PATCH 07/12] Whitespace removed --- wplay/about_changer.py | 3 --- wplay/get_media.py | 3 --- wplay/message_service.py | 3 --- wplay/online_tracker.py | 1 - wplay/schedule_message.py | 1 - wplay/target_info.py | 1 - 6 files changed, 12 deletions(-) diff --git a/wplay/about_changer.py b/wplay/about_changer.py index d6235669..17b8f8ae 100644 --- a/wplay/about_changer.py +++ b/wplay/about_changer.py @@ -18,15 +18,12 @@ async def about_changer(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #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) - query: str = str(input("What's the news theme? : ")) await page.waitForSelector(whatsapp_selectors_dict['profile_photo_element'], visible=True) diff --git a/wplay/get_media.py b/wplay/get_media.py index bc43a518..7c3e0327 100644 --- a/wplay/get_media.py +++ b/wplay/get_media.py @@ -16,15 +16,12 @@ async def get_profile_photos(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #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) - total_contacts = int(input("Please provide total whatsapp contacts: ")) loop = round(total_contacts/7) images_list = [] diff --git a/wplay/message_service.py b/wplay/message_service.py index 364d966d..966bb1c0 100644 --- a/wplay/message_service.py +++ b/wplay/message_service.py @@ -45,12 +45,10 @@ async def message_service(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #Minimizing the Window after Target Select print("Browser Minimized") Minimize = win32gui.GetForegroundWindow() win32gui.ShowWindow(Minimize, win32con.SW_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.") @@ -87,6 +85,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/online_tracker.py b/wplay/online_tracker.py index e842bd5e..a07209c2 100644 --- a/wplay/online_tracker.py +++ b/wplay/online_tracker.py @@ -36,7 +36,6 @@ async def tracker(target): print("Browser Minimized") Minimize = win32gui.GetForegroundWindow() win32gui.ShowWindow(Minimize, win32con.SW_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 aa48f016..c4dccfe7 100644 --- a/wplay/schedule_message.py +++ b/wplay/schedule_message.py @@ -29,7 +29,6 @@ async def schedule_message(target): print("Browser Minimized") Minimize = win32gui.GetForegroundWindow() win32gui.ShowWindow(Minimize, win32con.SW_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 7ef95554..d38b1e7f 100644 --- a/wplay/target_info.py +++ b/wplay/target_info.py @@ -107,7 +107,6 @@ async def target_info(target): print("Browser Minimized") Minimize = win32gui.GetForegroundWindow() win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) - """ # to find location by ip address print('Get you ipinfo token from https://ipinfo.io/account') From 62d3c5b6d18503384acedd83d340a2542c82f40c Mon Sep 17 00:00:00 2001 From: Soumya Shaw <37841510+soumyashaw@users.noreply.github.com> Date: Fri, 22 May 2020 00:14:54 +0530 Subject: [PATCH 08/12] Removed unused imports --- wplay/get_news.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wplay/get_news.py b/wplay/get_news.py index d4347b9f..52a0af8c 100644 --- a/wplay/get_news.py +++ b/wplay/get_news.py @@ -1,7 +1,6 @@ # region IMPORTS from pathlib import Path import time -import os import win32gui, win32con from newsapi.newsapi_client import NewsApiClient @@ -44,7 +43,6 @@ def fetch_news(country_code): print("Browser Minimized") Minimize = win32gui.GetForegroundWindow() win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) - country = input("Enter your country code (ex: us or in): ") while True: try: From f04f84cdd4f65cfca3becfec4b1d4098028adf9d Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Fri, 22 May 2020 00:25:31 +0530 Subject: [PATCH 09/12] Delete get_target_media.py --- wplay/get_target_media.py | 47 --------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 wplay/get_target_media.py diff --git a/wplay/get_target_media.py b/wplay/get_target_media.py deleted file mode 100644 index d6e142e6..00000000 --- a/wplay/get_target_media.py +++ /dev/null @@ -1,47 +0,0 @@ -# region Imports -import time -from pathlib import Path - -from wplay.utils import browser_config -from wplay.utils.Logger import Logger -from wplay.utils.helpers import profile_photos_path -# endregion - - -# region LOGGER -__logger = Logger(Path(__file__).name) -# endregion - -#-----------------------------------------------chnage 1: function name----------------------------------- -async def get_target_profile_photos(): - page, _ = await browser_config.configure_browser_and_load_whatsapp() - total_contacts = int(input("Please provide total whatsapp contacts: ")) - loop = round(total_contacts/7) - images_list = [] - - await page.waitForSelector('#pane-side > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div > div > img') - - for c in range(loop): - for i in range(1, 18): - selector = f"#pane-side > div:nth-child(1) > div > div > div:nth-child({i}) > div > div > div > div > img" - try: - await page.waitForSelector(selector, timeout=2000) - image_url = await page.evaluate(f'document.querySelector("{selector}").getAttribute("src")') - print(f"{c}:{i}-{image_url}") - if image_url not in images_list: - images_list.append(image_url) - except Exception as e: - print("No profile image found") - await page.evaluate("document.querySelector('#pane-side').scrollBy(0, 500)") - - for count in range(len(images_list)): - try: - viewSource = await page.goto(images_list[count]) - f = open(profile_photos_path / f'{count}.jpg', 'wb') - f.write(await viewSource.buffer()) - f.close() - except Exception as e: - print("Error saving image") - - print("Saved all the images to media_folder.") - time.sleep(5) From 98af9b25dd1579a67eae103fd52b5f30060c5079 Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Fri, 22 May 2020 16:35:51 +0530 Subject: [PATCH 10/12] Minimize the browser window --- wplay/about_changer.py | 8 +------- wplay/broadcast_message.py | 12 +----------- wplay/download_media.py | 8 +------- wplay/get_media.py | 8 +------- wplay/get_news.py | 6 +----- wplay/message_blast.py | 7 +------ wplay/message_service.py | 6 +----- wplay/message_timer.py | 7 +------ wplay/online_tracker.py | 5 +---- wplay/schedule_message.py | 6 +----- wplay/target_info.py | 6 +----- wplay/terminal_chat.py | 5 +---- wplay/utils/browser_config.py | 17 +++++++++++++++++ 13 files changed, 29 insertions(+), 72 deletions(-) diff --git a/wplay/about_changer.py b/wplay/about_changer.py index 17b8f8ae..ab8df28f 100644 --- a/wplay/about_changer.py +++ b/wplay/about_changer.py @@ -2,7 +2,6 @@ import time import os import sys -import win32gui, win32con from newsapi.newsapi_client import NewsApiClient import requests @@ -18,12 +17,7 @@ async def about_changer(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #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) + 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 cc82916b..8b9c69b6 100644 --- a/wplay/broadcast_message.py +++ b/wplay/broadcast_message.py @@ -2,8 +2,6 @@ from tkinter import Tk from tkinter.filedialog import askopenfile from pathlib import Path -import time -import win32gui, win32con from wplay.utils import browser_config from wplay.utils.target_search import search_target_by_number @@ -24,15 +22,7 @@ class InvalidNumber(Exception): def ProcessNumbers(): __logger.info("Processing numbers.") - - #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) - + 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 3dbec701..85879faf 100644 --- a/wplay/download_media.py +++ b/wplay/download_media.py @@ -1,6 +1,5 @@ # region Imports from pathlib import Path -import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -32,12 +31,7 @@ async def download_media(target): ) else: await target_select.manual_select_target(page) - - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) - + 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 7c3e0327..b2467a0c 100644 --- a/wplay/get_media.py +++ b/wplay/get_media.py @@ -1,7 +1,6 @@ # region Imports import time from pathlib import Path -import win32gui, win32con from wplay.utils import browser_config from wplay.utils.Logger import Logger @@ -16,12 +15,7 @@ async def get_profile_photos(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #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) + 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 52a0af8c..6c9c0868 100644 --- a/wplay/get_news.py +++ b/wplay/get_news.py @@ -1,7 +1,6 @@ # region IMPORTS from pathlib import Path import time -import win32gui, win32con from newsapi.newsapi_client import NewsApiClient @@ -39,10 +38,7 @@ def fetch_news(country_code): else: await target_select.manual_select_target(page) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + 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 d1590017..4d1b182c 100644 --- a/wplay/message_blast.py +++ b/wplay/message_blast.py @@ -1,7 +1,6 @@ # region IMPORTS from pathlib import Path from typing import List -import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -24,11 +23,7 @@ async def message_blast(target: str): else: await target_select.manual_select_target(page) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) - + 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 966bb1c0..8259e334 100644 --- a/wplay/message_service.py +++ b/wplay/message_service.py @@ -3,7 +3,6 @@ import threading import time import json -import win32gui, win32con from wplay.utils import browser_config from wplay.utils.target_search import search_target_by_number @@ -45,10 +44,7 @@ async def message_service(): page, _ = await browser_config.configure_browser_and_load_whatsapp() - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + 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.") diff --git a/wplay/message_timer.py b/wplay/message_timer.py index 28cb5290..a7e312b0 100644 --- a/wplay/message_timer.py +++ b/wplay/message_timer.py @@ -1,7 +1,6 @@ # region IMPORTS import time import random -import win32gui, win32con from pathlib import Path from wplay.utils import browser_config @@ -30,11 +29,7 @@ async def message_timer(target): else: await target_select.manual_select_target(page) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) - + 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 a07209c2..5dc86fc2 100644 --- a/wplay/online_tracker.py +++ b/wplay/online_tracker.py @@ -32,10 +32,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) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + 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 c4dccfe7..4c38a4f6 100644 --- a/wplay/schedule_message.py +++ b/wplay/schedule_message.py @@ -3,7 +3,6 @@ from pathlib import Path import time import sys -import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -25,10 +24,7 @@ async def schedule_message(target): else: await target_select.manual_select_target(page) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + 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 d38b1e7f..ce96a94c 100644 --- a/wplay/target_info.py +++ b/wplay/target_info.py @@ -8,7 +8,6 @@ from phonenumbers import timezone import re import sys -import win32gui, win32con from pathlib import Path from wplay.utils.Logger import Logger # end IMPORTS @@ -103,10 +102,7 @@ async def target_info(target): else: await target_select.manual_select_target(page) - #Minimizing the Window after Target Select - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + 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 5ed0ecae..a4fd0d86 100644 --- a/wplay/terminal_chat.py +++ b/wplay/terminal_chat.py @@ -1,6 +1,5 @@ # region IMPORTS from pathlib import Path -import win32gui, win32con from wplay.utils import browser_config from wplay.utils import target_search @@ -38,9 +37,7 @@ async def chat(target): while True: #Minimizing the Window after Target Select if (initial_minimize==True): - print("Browser Minimized") - Minimize = win32gui.GetForegroundWindow() - win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE) + browser_config.minimize() initial_minimize = False await getMessages(page, target) 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 ''' From ab84899e9d59b7b7662fe3f5f3e8cd676717aa15 Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Fri, 22 May 2020 16:39:04 +0530 Subject: [PATCH 11/12] Update online_tracker.py --- wplay/online_tracker.py | 1 - 1 file changed, 1 deletion(-) diff --git a/wplay/online_tracker.py b/wplay/online_tracker.py index 5dc86fc2..6a8f96ff 100644 --- a/wplay/online_tracker.py +++ b/wplay/online_tracker.py @@ -1,5 +1,4 @@ import time -import win32gui, win32con from pathlib import Path from datetime import datetime from playsound import playsound From bd2d09861dca3ddd7cfc7858f081b12f95dc370f Mon Sep 17 00:00:00 2001 From: soumyashaw Date: Fri, 22 May 2020 16:56:40 +0530 Subject: [PATCH 12/12] Updated code acoording to PEP8 --- wplay/terminal_chat.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wplay/terminal_chat.py b/wplay/terminal_chat.py index a4fd0d86..848c9098 100644 --- a/wplay/terminal_chat.py +++ b/wplay/terminal_chat.py @@ -35,8 +35,7 @@ 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: - #Minimizing the Window after Target Select - if (initial_minimize==True): + if (initial_minimize): browser_config.minimize() initial_minimize = False @@ -79,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