-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwhatsapp-otp.py
51 lines (35 loc) · 1.08 KB
/
whatsapp-otp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
# Required package
# In[ ]:
# pip install firebase
# pip install requests
# pip install firebase_admin
# In[1]:
import pywhatkit
import requests
import math, random
from firebase import firebase
from firebase_admin import credentials, initialize_app, storage, firestore
cred = credentials.Certificate(r"serviceAccountKey.json")
initialize_app(cred, {'storageBucket': 'stock-data-fc41e.appspot.com'})
db = firestore.client()
# In[2]:
doc_ref = db.collection(u'user').document(u'data')
phnum = doc_ref.get(field_paths={'phone'}).to_dict().get('phone')
def generateOTP() :
digits = "0123456789"
OTP = ""
for i in range(4) :
OTP += digits[math.floor(random.random() * 10)]
doc_ref = db.collection(u'user').document(u'data')
doc_ref.set({
u'otp': OTP
}, merge=True)
return OTP
try:
requests.post('https://whatsapp-node-api.herokuapp.com/chat/sendmessage/'+phnum, json={'message': 'Your OTP is '+generateOTP()})
print("Successfully Sent!")
except:
print("An Unexpected Error!")