Created
August 31, 2019 14:55
-
-
Save harilee1325/ecf95c75d32d3d9bf7a6c241fcbdbeeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request | |
import math, random | |
from pyfcm import FCMNotification | |
from twilio.rest import Client | |
import zerosms | |
import getpass | |
app = Flask(__name__) | |
push_service = FCMNotification(api_key="AIzaSyC9gDv-1jLHCRQjJJxvlhJc9yMl_SNxmfY") | |
account_sid = 'ACb8a3113f596c65078adc4ad948376230' | |
auth_token = 'a796a75df42f962dc4910a6f52c71801' | |
client = Client(account_sid, auth_token) | |
def generateOTP() : | |
# Declare a digits variable | |
# which stores all digits | |
digits = "0123456789" | |
OTP = "" | |
# length of password can be chaged | |
# by changing value in range | |
for i in range(4) : | |
OTP += digits[math.floor(random.random() * 10)] | |
return OTP | |
#+12013544476 | |
@app.route('/otp/<string:fcm_token>', methods=['GET']) | |
def otpRoute (fcm_token): | |
otp = generateOTP() | |
# message = client.messages \ | |
# .create( | |
# body="Join Earth's mightiest heroes. Like Kevin Bacon.", | |
# from_=+12013544476, | |
# to=+918075687141 | |
# ) | |
# print(message.sid) | |
zerosms.sms(phno=8075687141,passwd="harilee1329",message='helloworld!!',receivernum=8075687141) | |
sendNotificationOtp(otp, fcm_token) | |
return jsonify({'success':'yes','otp':otp}) | |
# OR initialize with proxies | |
#push_service = FCMNotification(api_key="AIzaSyC9gDv-1jLHCRQjJJxvlhJc9yMl_SNxmfY") | |
# Your api-key can be gotten from: https://console.firebase.google.com/project/<project-name>/settings/cloudmessaging | |
#for sending a message to a single device | |
def sendNotificationOtp (otpText, fcmToken): | |
# registration_id = fcmToken | |
registration_id = "ddUTUWWIWQE:APA91bGcb1bJsuvmXnA1VRwZKLMPeVlv8csskBB_TQ38r-b76_pH6MkZ4tnMvPa2nyz0L62bYD8Dt3qL2pMIiXP11EkH6TUIas0_oKaerKPi-BMTtSt8Hh0rEKrPFAwYeKi_X6bLoO8z" | |
message_title = "Bounce" | |
message_body = "Thank you for signing up with Bounce your OTP for signing up is "+otpText | |
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body) | |
print (result) | |
def sendNotificationOther (fcmToken): | |
registration_id = "ddUTUWWIWQE:APA91bGcb1bJsuvmXnA1VRwZKLMPeVlv8csskBB_TQ38r-b76_pH6MkZ4tnMvPa2nyz0L62bYD8Dt3qL2pMIiXP11EkH6TUIas0_oKaerKPi-BMTtSt8Hh0rEKrPFAwYeKi_X6bLoO8z" | |
message_title = "Bounce" | |
message_body = "wE ARE GONNA WIN" | |
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body) | |
print (result) | |
# Send to multiple devices by passing a list of ids. | |
# registration_ids = ["<device registration_id 1>", "<device registration_id 2>", ...] | |
# message_title = "Uber update" | |
# message_body = "Hope you're having fun this weekend, don't forget to check today's news" | |
# result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body) | |
# print result | |
if __name__=="_main__": | |
app.run(debug=True, port=8080) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment