I have an application in flask and I tried to insert within that application a code to automatically send messages to whatssap.
- Code:
import pywhatkit as pwk
import time
def whats():
tim = time.localtime()
hour = int(time.strftime("%H", tim))
min = int(time.strftime("%M", tim))
if min==59:
min = 0
else:
min += 1
# using Exception Handling to avoid unexpected errors
try:
# sending message in Whatsapp in India so using Indian dial code (+91)
pwk.sendwhatmsg("+5587988758805", "Trabalhador sem EPI!", hour, min)
print("Message Sent!") #Prints success message in console
# error message
except:
print("Error in sending the message")
Both codes are working perfectly, but when I put the two codes together the code doesn't compile.
I did some tests:
I tried to just
import pywhatkit as pwkin the flask application;I tried to use the code in another python file and import;
I tried to put both codes together in same python file.
In all situations the code does not compile, when I debug the code for test 1, I get the following error:
Exception has occurred: SystemExit 3
File "C:\Users\diego\codes\Working\modify.py", line 96, in <module>
app.run(debug=True)
Why can't I compile my code when I put the pywhatkit library inside the flask application?