|
| 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,45 @@ def sendwhatmsg_instantly( |
40 | 42 | if tab_close: |
41 | 43 | core.close_tab(wait_time=close_time) |
42 | 44 |
|
| 45 | +def sendwhatdoc_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) |
43 | 84 |
|
44 | 85 | def sendwhatmsg( |
45 | 86 | phone_no: str, |
|
0 commit comments