Skip to content

Commit e5b7c7b

Browse files
Merge pull request #253 from SigireddyBalasai/master
Send Document and Videos instantly
2 parents 30063ba + 1720030 commit e5b7c7b

File tree

7 files changed

+93
-68
lines changed

7 files changed

+93
-68
lines changed

pywhatkit/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Version 5.2
1+
""" Version 5.2
22
# Status: Stable
33
# Documentation: https://github.com/Ankit404butfound/PyWhatKit/wiki
44
# Report Bugs and Feature Requests here: https://github.com/Ankit404butfound/PyWhatKit/issues
55
# For further Information, Join our Discord: https://discord.gg/62Yf5mushu
6-
6+
"""
77
__VERSION__ = "Version 5.3 (Stable)"
88

99
from platform import system
1010

1111
from pywhatkit.ascii_art import image_to_ascii_art
1212
from pywhatkit.handwriting import text_to_handwriting
1313
from pywhatkit.mail import send_hmail, send_mail
14-
from pywhatkit.misc import info, playonyt, search, show_history, take_screenshot
14+
from pywhatkit.misc import info, playonyt, search, show_history
1515
from pywhatkit.sc import cancel_shutdown, shutdown
1616
from pywhatkit.whats import (
1717
open_web,
@@ -20,7 +20,8 @@
2020
sendwhatmsg_to_group,
2121
sendwhatmsg_to_group_instantly,
2222
sendwhats_image,
23-
sendwhatdoc_immediately
23+
sendwhatdoc_immediately,
24+
sendimg_or_video_immediately
2425
)
2526

2627
_system = system().lower()

pywhatkit/core/core.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ def findtextbox() -> None:
4646
click()
4747

4848

49+
def find_link():
50+
dir_path = os.path.dirname(os.path.realpath(__file__))
51+
location = locateOnScreen(f"{dir_path}\\data\\link.png")
52+
print(location)
53+
try:
54+
moveTo(location[0] + location[2]/2, location[1] + location[3]/2)
55+
click()
56+
except Exception:
57+
location = locateOnScreen(f"{dir_path}\\data\\link2.png")
58+
moveTo(location[0] + location[2]/2, location[1] + location[3]/2)
59+
print(location)
60+
click()
61+
def find_document():
62+
dir_path = os.path.dirname(os.path.realpath(__file__))
63+
location = locateOnScreen(f"{dir_path}\\data\\document.png")
64+
print(location)
65+
moveTo(location[0] + location[2]/2, location[1] + location[3]/2)
66+
click()
67+
68+
def find_photo_or_video():
69+
dir_path = os.path.dirname(os.path.realpath(__file__))
70+
location = locateOnScreen(f"{dir_path}\\data\\photo_or_video.png")
71+
print(location)
72+
moveTo(location[0] + location[2]/2, location[1] + location[3]/2)
73+
click()
74+
4975
def check_connection() -> None:
5076
"""Check the Internet connection of the Host Machine"""
5177

pywhatkit/core/data/document.png

317 Bytes
Loading
File renamed without changes.

pywhatkit/core/data/link2.png

442 Bytes
Loading
434 Bytes
Loading

pywhatkit/whats.py

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818

1919
def sendwhatmsg_instantly(
20-
phone_no: str,
21-
message: str,
22-
wait_time: int = 15,
23-
tab_close: bool = False,
24-
close_time: int = 3,
20+
phone_no: str,
21+
message: str,
22+
wait_time: int = 15,
23+
tab_close: bool = False,
24+
close_time: int = 3,
2525
) -> None:
2626
"""Send WhatsApp Message Instantly"""
2727

@@ -42,12 +42,13 @@ def sendwhatmsg_instantly(
4242
if tab_close:
4343
core.close_tab(wait_time=close_time)
4444

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,
45+
46+
def sendimg_or_video_immediately(
47+
phone_no: str,
48+
path: str,
49+
wait_time: int = 15,
50+
tab_close: bool = False,
51+
close_time: int = 3,
5152
) -> None:
5253
"""Send WhatsApp Message Instantly"""
5354

@@ -59,13 +60,11 @@ def sendwhatimg_immediately(
5960
raise exceptions.InvalidPhoneNumber("Invalid Phone Number.")
6061

6162
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)
63+
time.sleep(wait_time)
64+
core.find_link()
65+
time.sleep(1)
66+
core.find_photo_or_video()
67+
6968
pyperclip.copy(os.path.abspath(path))
7069
print("Copied")
7170
time.sleep(1)
@@ -81,12 +80,13 @@ def sendwhatimg_immediately(
8180
keyboard.release("enter")
8281
if tab_close:
8382
core.close_tab(wait_time=close_time)
83+
8484
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,
85+
phone_no: str,
86+
path: str,
87+
wait_time: int = 15,
88+
tab_close: bool = True,
89+
close_time: int = 3,
9090
) -> None:
9191
"""Send WhatsApp Message Instantly"""
9292

@@ -98,13 +98,10 @@ def sendwhatdoc_immediately(
9898
raise exceptions.InvalidPhoneNumber("Invalid Phone Number.")
9999

100100
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)
101+
time.sleep(wait_time)
102+
core.find_link()
103+
time.sleep(1)
104+
core.find_document()
108105
pyperclip.copy(os.path.abspath(path))
109106
print("Copied")
110107
time.sleep(1)
@@ -121,14 +118,15 @@ def sendwhatdoc_immediately(
121118
if tab_close:
122119
core.close_tab(wait_time=close_time)
123120

121+
124122
def sendwhatmsg(
125-
phone_no: str,
126-
message: str,
127-
time_hour: int,
128-
time_min: int,
129-
wait_time: int = 15,
130-
tab_close: bool = False,
131-
close_time: int = 3,
123+
phone_no: str,
124+
message: str,
125+
time_hour: int,
126+
time_min: int,
127+
wait_time: int = 15,
128+
tab_close: bool = False,
129+
close_time: int = 3,
132130
) -> None:
133131
"""Send a WhatsApp Message at a Certain Time"""
134132
if not core.check_number(number=phone_no):
@@ -166,13 +164,13 @@ def sendwhatmsg(
166164

167165

168166
def sendwhatmsg_to_group(
169-
group_id: str,
170-
message: str,
171-
time_hour: int,
172-
time_min: int,
173-
wait_time: int = 15,
174-
tab_close: bool = False,
175-
close_time: int = 3,
167+
group_id: str,
168+
message: str,
169+
time_hour: int,
170+
time_min: int,
171+
wait_time: int = 15,
172+
tab_close: bool = False,
173+
close_time: int = 3,
176174
) -> None:
177175
"""Send WhatsApp Message to a Group at a Certain Time"""
178176

@@ -204,11 +202,11 @@ def sendwhatmsg_to_group(
204202

205203

206204
def sendwhatmsg_to_group_instantly(
207-
group_id: str,
208-
message: str,
209-
wait_time: int = 15,
210-
tab_close: bool = False,
211-
close_time: int = 3,
205+
group_id: str,
206+
message: str,
207+
wait_time: int = 15,
208+
tab_close: bool = False,
209+
close_time: int = 3,
212210
) -> None:
213211
"""Send WhatsApp Message to a Group Instantly"""
214212

@@ -221,13 +219,13 @@ def sendwhatmsg_to_group_instantly(
221219

222220

223221
def sendwhatsmsg_to_all(
224-
phone_nos: List[str],
225-
message: str,
226-
time_hour: int,
227-
time_min: int,
228-
wait_time: int = 15,
229-
tab_close: bool = False,
230-
close_time: int = 3,
222+
phone_nos: List[str],
223+
message: str,
224+
time_hour: int,
225+
time_min: int,
226+
wait_time: int = 15,
227+
tab_close: bool = False,
228+
close_time: int = 3,
231229
):
232230
for phone_no in phone_nos:
233231
sendwhatmsg(
@@ -236,14 +234,14 @@ def sendwhatsmsg_to_all(
236234

237235

238236
def sendwhats_image(
239-
receiver: str,
240-
img_path: str,
241-
time_hour: int,
242-
time_min: int,
243-
caption: str = "",
244-
wait_time: int = 15,
245-
tab_close: bool = False,
246-
close_time: int = 3,
237+
receiver: str,
238+
img_path: str,
239+
time_hour: int,
240+
time_min: int,
241+
caption: str = "",
242+
wait_time: int = 15,
243+
tab_close: bool = False,
244+
close_time: int = 3,
247245
) -> None:
248246
"""Send Image to a WhatsApp Contact or Group at a Certain Time"""
249247

0 commit comments

Comments
 (0)