Skip to content

Commit 77248a9

Browse files
authored
Merge branch 'master' into master
2 parents 7c55919 + 4a86db1 commit 77248a9

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Bug Report
33
about: Create a Report to help us Improve
44
title: ''
5-
labels: ''
5+
labels: 'bug'
66
assignees: ''
77

88
---
@@ -23,8 +23,8 @@ If applicable, add Screenshots to help explain your Problem
2323

2424
- OS: [e.g. Windows 10]
2525
- Browser: [e.g. Microsoft Edge, Google Chrome]
26-
- Python: [e.g. 3.10.0]
27-
- PyWhatKit: [e.g. 5.2]
26+
- Python: [e.g. 3.10.1]
27+
- PyWhatKit: [e.g. 5.3]
2828

2929
You can Check the PyWhatKit Version using
3030

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Feature Request
33
about: Suggest an Idea for this Project
44
title: ''
5-
labels: ''
5+
labels: 'feature-request'
66
assignees: ''
77

88
---

pywhatkit/core/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class InternetException(Exception):
2222
pass
2323

2424

25+
class InvalidPhoneNumber(Exception):
26+
"""
27+
Phone number given is invalid
28+
"""
29+
30+
pass
31+
32+
2533
class UnsupportedEmailProvider(Exception):
2634
"""
2735
Email provider used to send the Email is not supported

pywhatkit/whats.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import webbrowser as web
33
from datetime import datetime
4+
from re import fullmatch
45
from urllib.parse import quote
56

67
import pyautogui as pg
@@ -24,6 +25,10 @@ def sendwhatmsg_instantly(
2425
if not core.check_number(number=phone_no):
2526
raise exceptions.CountryCodeException("Country Code Missing in Phone Number!")
2627

28+
phone_no = phone_no.replace(" ", "")
29+
if not fullmatch(r"^\+?[0-9]{2,4}\s?[0-9]{10}$", phone_no):
30+
raise exceptions.InvalidPhoneNumber("Invalid Phone Number.")
31+
2732
web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
2833
time.sleep(4)
2934
pg.click(core.WIDTH / 2, core.HEIGHT / 2)
@@ -48,6 +53,10 @@ def sendwhatmsg(
4853
if not core.check_number(number=phone_no):
4954
raise exceptions.CountryCodeException("Country Code Missing in Phone Number!")
5055

56+
phone_no = phone_no.replace(" ", "")
57+
if not fullmatch(r"^\+?[0-9]{2,4}[0-9]{10}$", phone_no):
58+
raise exceptions.InvalidPhoneNumber("Invalid Phone Number.")
59+
5160
if time_hour not in range(25) or time_min not in range(60):
5261
raise Warning("Invalid Time Format!")
5362

@@ -133,6 +142,8 @@ def sendwhatmsg_to_group_instantly(
133142
def sendwhats_image(
134143
receiver: str,
135144
img_path: str,
145+
time_hour: int,
146+
time_min: int,
136147
caption: str = "",
137148
wait_time: int = 15,
138149
tab_close: bool = False,
@@ -144,6 +155,23 @@ def sendwhats_image(
144155
raise exceptions.CountryCodeException("Country Code Missing in Phone Number!")
145156

146157
current_time = time.localtime()
158+
left_time = datetime.strptime(
159+
f"{time_hour}:{time_min}:0", "%H:%M:%S"
160+
) - datetime.strptime(
161+
f"{current_time.tm_hour}:{current_time.tm_min}:{current_time.tm_sec}",
162+
"%H:%M:%S",
163+
)
164+
165+
if left_time.seconds < wait_time:
166+
raise exceptions.CallTimeException(
167+
"Call Time must be Greater than Wait Time as WhatsApp Web takes some Time to Load!"
168+
)
169+
170+
sleep_time = left_time.seconds - wait_time
171+
print(
172+
f"In {sleep_time} Seconds WhatsApp will open and after {wait_time} Seconds Image will be Delivered!"
173+
)
174+
time.sleep(sleep_time)
147175
core.send_image(
148176
path=img_path, caption=caption, receiver=receiver, wait_time=wait_time
149177
)

0 commit comments

Comments
 (0)