|
| 1 | +import os |
1 | 2 | import time |
2 | 3 | import webbrowser as web |
3 | 4 | from datetime import datetime |
4 | 5 | from re import fullmatch |
5 | 6 | from typing import List |
6 | 7 | from urllib.parse import quote |
7 | | - |
| 8 | +import paperclip |
8 | 9 | import pyautogui as pg |
9 | | - |
| 10 | +import pyperclip |
| 11 | +import keyboard |
10 | 12 | from pywhatkit.core import core, exceptions, log |
11 | 13 |
|
12 | 14 | pg.FAILSAFE = False |
@@ -40,6 +42,84 @@ def sendwhatmsg_instantly( |
40 | 42 | if tab_close: |
41 | 43 | core.close_tab(wait_time=close_time) |
42 | 44 |
|
| 45 | +def sendwhatimg_immediately( |
| 46 | + phone_no: str, |
| 47 | + path: str, |
| 48 | + wait_time: int = 15, |
| 49 | + tab_close: bool = False, |
| 50 | + close_time: int = 3, |
| 51 | +) -> None: |
| 52 | + """Send WhatsApp Message Instantly""" |
| 53 | + |
| 54 | + if not core.check_number(number=phone_no): |
| 55 | + raise exceptions.CountryCodeException("Country Code Missing in Phone Number!") |
| 56 | + |
| 57 | + phone_no = phone_no.replace(" ", "") |
| 58 | + if not fullmatch(r"^\+?[0-9]{2,4}\s?[0-9]{9,15}", phone_no): |
| 59 | + raise exceptions.InvalidPhoneNumber("Invalid Phone Number.") |
| 60 | + |
| 61 | + web.open(f"https://web.whatsapp.com/send?phone={phone_no}") |
| 62 | + time.sleep(4) |
| 63 | + time.sleep(wait_time - 4) |
| 64 | + (ps_x, ps_y) = pg.size() |
| 65 | + as_x = ps_x / 1920 |
| 66 | + as_y = ps_y / 1080 |
| 67 | + pg.click(671 * as_x, 964 * as_y) |
| 68 | + pg.click(675 * as_x, 878 * as_y) |
| 69 | + pyperclip.copy(os.path.abspath(path)) |
| 70 | + print("Copied") |
| 71 | + time.sleep(1) |
| 72 | + keyboard.press("ctrl") |
| 73 | + keyboard.press("v") |
| 74 | + keyboard.release("v") |
| 75 | + keyboard.release("ctrl") |
| 76 | + time.sleep(1) |
| 77 | + keyboard.press("enter") |
| 78 | + keyboard.release("enter") |
| 79 | + time.sleep(1) |
| 80 | + keyboard.press("enter") |
| 81 | + keyboard.release("enter") |
| 82 | + if tab_close: |
| 83 | + core.close_tab(wait_time=close_time) |
| 84 | +def sendwhatdoc_immediately( |
| 85 | + phone_no: str, |
| 86 | + path: str, |
| 87 | + wait_time: int = 15, |
| 88 | + tab_close: bool = False, |
| 89 | + close_time: int = 3, |
| 90 | +) -> None: |
| 91 | + """Send WhatsApp Message Instantly""" |
| 92 | + |
| 93 | + if not core.check_number(number=phone_no): |
| 94 | + raise exceptions.CountryCodeException("Country Code Missing in Phone Number!") |
| 95 | + |
| 96 | + phone_no = phone_no.replace(" ", "") |
| 97 | + if not fullmatch(r"^\+?[0-9]{2,4}\s?[0-9]{9,15}", phone_no): |
| 98 | + raise exceptions.InvalidPhoneNumber("Invalid Phone Number.") |
| 99 | + |
| 100 | + web.open(f"https://web.whatsapp.com/send?phone={phone_no}") |
| 101 | + time.sleep(4) |
| 102 | + time.sleep(wait_time - 4) |
| 103 | + (ps_x, ps_y) = pg.size() |
| 104 | + as_x = ps_x / 1920 |
| 105 | + as_y = ps_y / 1080 |
| 106 | + pg.click(671 * as_x, 964 * as_y) |
| 107 | + pg.click(677 * as_x, 625 * as_y) |
| 108 | + pyperclip.copy(os.path.abspath(path)) |
| 109 | + print("Copied") |
| 110 | + time.sleep(1) |
| 111 | + keyboard.press("ctrl") |
| 112 | + keyboard.press("v") |
| 113 | + keyboard.release("v") |
| 114 | + keyboard.release("ctrl") |
| 115 | + time.sleep(1) |
| 116 | + keyboard.press("enter") |
| 117 | + keyboard.release("enter") |
| 118 | + time.sleep(1) |
| 119 | + keyboard.press("enter") |
| 120 | + keyboard.release("enter") |
| 121 | + if tab_close: |
| 122 | + core.close_tab(wait_time=close_time) |
43 | 123 |
|
44 | 124 | def sendwhatmsg( |
45 | 125 | phone_no: str, |
|
0 commit comments