Example #1
0
def create_event():
    data = request.get_json()
    club_schema = ClubsSchema()
    club_user = Clubs(public_id=str(uuid.uuid4()),
                      name=data['name'],
                      description=data['description'],
                      time_start=data['time_start'],
                      time_end=data['time_end'],
                      date_week=data['date_week'],
                      event_date=data['event_date'],
                      location=data['location'])
    db.session.add(club_user)
    db.session.commit()

    push_service = FCMNotification(
        api_key=
        "AAAAp-1UTKo:APA91bF9KFpF7_cBlfSohNuNTJL-UpLOKSp1b4S_vG44C3GezCsFM-86ltgf152LkZc_ngUblPWVk4ZVRpJZxH8TYuKGt-zje81fYb3A1AQAD0lY_W9EEOs3-nTH99YeRDIRuoIkWp4v"
    )

    registration_id = "ftKlJ-8Vq0E:APA91bFUgrXrt6LdW4_j3-Pe6IBYZwE26n5pQ-JJW-UnUp1pQx-bPe1tQgmBr5e0XfHs6dkStradmxybvD92CjmST328CrD9YU1UIhRKxq6ZAhY-2ox2Q1oA8bziZeQ9y16L9n_ULmnXwBOIDG3LkxVSwgRn5m_7_Q"
    message_title = "New Event Posted"
    message_body = club_user.name + ' ' + club_user.description + ' ' + club_user.time_start + ' ' + club_user.time_end + ' ' + club_user.date_week + ' ' + club_user.event_date + ' ' + club_user.location
    result = push_service.notify_single_device(registration_id=registration_id,
                                               message_title=message_title,
                                               message_body=message_body)
    print result
    return jsonify({
        'message': 'Club event created',
        'secret_id': club_user.public_id
    })
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument(name="message_title", type=str, location="json")
     parser.add_argument(name="message_body", type=str, location="json")
     body = parser.parse_args()
     message_title = body["message_title"]
     message_body = body["message_body"]
     datet = datetime.datetime.utcnow() + datetime.timedelta(hours=7)
     if message_title is None or message_body is None:
         return {"message": "bắn noti cc thiếu"}, 401
     notification = Notification(message_body=message_body,
                                 message_title=message_title,
                                 datetime=str(datet),
                                 is_read=False)
     notification.save()
     listnoti = Notification.objects()
     if len(list(listnoti)) > 10:
         listnoti = list(listnoti)[:len(listnoti) - 11]
         for noti in listnoti:
             noti.delete()
     apikey = "AAAAhgLLpbs:APA91bGLuFvqDwvWs7L7RNnMHwus426M1fi5oLSP2azB5jOhB2jW2i91uIZF7jrECoyUYk-c-h5yyp4DY0oKFhEgg3S6o7fsv7dc-M5aBDdwxbYaWgXVn3HFEqImNYEm6xfyeMqb4lAR"
     push_service = FCMNotification(api_key=apikey)
     push_service.notify_topic_subscribers(topic_name="user",
                                           message_body=message_body,
                                           message_title=message_title)
     return mlab.item2json(Notification.objects().with_id(notification.id))
Example #3
0
 def post(self, id):
     order = Oder.objects().with_id(id)
     order.update(set__is_Shipping=True, set__is_Received=True)
     user = order.user
     if user.token is not None:
         apikey = "AAAAhgLLpbs:APA91bGLuFvqDwvWs7L7RNnMHwus426M1fi5oLSP2azB5jOhB2jW2i91uIZF7jrECoyUYk-c-h5yyp4DY0oKFhEgg3S6o7fsv7dc-M5aBDdwxbYaWgXVn3HFEqImNYEm6xfyeMqb4lAR"
         push_service = FCMNotification(api_key=apikey)
         push_service.notify_single_device(
             registration_id=user.token,
             message_body="Đơn hàng đã được giao cho shipper!",
             message_title="Chú ý!")
     return {"message": "OK"}, 200
Example #4
0
 def delete(self, id):
     oder = Oder.objects().with_id(id)
     oder.delete()
     user = oder.user
     if user.token is not None:
         apikey = "AAAAhgLLpbs:APA91bGLuFvqDwvWs7L7RNnMHwus426M1fi5oLSP2azB5jOhB2jW2i91uIZF7jrECoyUYk-c-h5yyp4DY0oKFhEgg3S6o7fsv7dc-M5aBDdwxbYaWgXVn3HFEqImNYEm6xfyeMqb4lAR"
         push_service = FCMNotification(api_key=apikey)
         push_service.notify_single_device(
             registration_id=user.token,
             message_body="Đơn hàng của bạn bị huỷ bỏ!",
             message_title="Cảm ơn bạn đã ghé thăm!")
     return {"message": "Ok"}, 200
Example #5
0
 def put(self, id):
     oder = Oder.objects().with_id(id)
     if (oder.is_Succues == True):
         return {"message": "Cộng rồi"}, 401
     oder.update(set__is_Succues=True,
                 set__is_Received=True,
                 set__is_Shipping=True)
     oder_add = Oder.objects().with_id(id)
     user = oder["user"]
     spend = float(oder["spend"])
     spend_user = float(user["total_spend"])
     total = spend + spend_user
     user.update(total_spend=total)
     if user.token is not None:
         name = "bạn"
     if user.name is not None:
         name = user.name
         apikey = "AAAAhgLLpbs:APA91bGLuFvqDwvWs7L7RNnMHwus426M1fi5oLSP2azB5jOhB2jW2i91uIZF7jrECoyUYk-c-h5yyp4DY0oKFhEgg3S6o7fsv7dc-M5aBDdwxbYaWgXVn3HFEqImNYEm6xfyeMqb4lAR"
         push_service = FCMNotification(api_key=apikey)
         push_service.notify_single_device(
             registration_id=user.token,
             message_body="Chúc bạn ngon miệng!",
             message_title="Cảm ơn " + name + "!")
     return user.get_json(), 200
Example #6
0
            color=color,
            tag=tag,
            body_loc_key=body_loc_key,
            body_loc_args=body_loc_args,
            title_loc_key=title_loc_key,
            title_loc_args=title_loc_args,
            content_available=content_available,
            **extra_kwargs)
        await self.send_request([payload])
        return self.parse_responses()[-1:][0]


if __name__ == '__main__':
    loop = asyncio.get_event_loop()

    push_service = FCMNotification(api_key=os.environ['FCM_SERVER_KEY'])
    apush_service = AsyncFCMNotification(api_key=os.environ['FCM_SERVER_KEY'],
                                         aiohttp_verify_ssl=False)
    reg_ids = [
        'fKk2D2q42ug:APA91bFxg0oQr7UzIn-4PC3ZUBOm3RJ66ML8cWiaOrvfAe9P9AFjYcAYatAjtchh84R78i3ghYLJR6j2xp4CkJ_wKtsvMMD2hZt-_ydHlSmtPuPEuB5V5VdmC5PGbWrc7ruzBnJPAdTy'
    ]
    for reg_id in reg_ids:
        # push_service.notify_single_device(
        #     registration_id=reg_id,
        #     message_title='Hi Max',
        #     message_body='This is a test of new pushes')
        loop.run_until_complete(
            apush_service.notify_single_device(
                registration_id=reg_id,
                message_title='Hi async',
                message_body='This is a test of new pushes'))
Example #7
0
from random import randint

from app.models.administrador import Administrador
from app.models.generic_respones import BasicReturn
from app.models.gerente import Gerente
from app.models.notificacion import NotificacionAdmin

from app.utils.security import get_current_gerente

from app.db.db import db


router = APIRouter(prefix="/sugerencia", tags=["sugerencia"])

push_service = FCMNotification(api_key=FIREBASE_TOKEN)


@router.post("", response_model=BasicReturn)
async def newSugerencia(
    contenido: str = Body(...,min_length=1,embed=True), gerente: Gerente = Depends(get_current_gerente)
):

    admins = await db.motor.find(Administrador)
    ind = randint(0, len(admins) - 1)
    responsable = admins[ind]
    solicitud = NotificacionAdmin(
        responsable=responsable,
        gerente=str(gerente.id),
        contenido=contenido,
        tipo=TipoNotificacion.sugerencia,
from flask import Flask, render_template, request
from pyfcm.fcm import FCMNotification

push_service = FCMNotification(
    api_key="AIzaSyDfv98w0EydT4wvpGQYy2tcGyOPs6EYcTE", env='app_engine')

app = Flask(__name__)


@app.route("/", methods=['GET', 'POST'])
def main():
    # return the rendered main.html
    return render_template('main.html')


@app.route("/sent.html", methods=['POST'])
def sent():
    # Get Notification from the form
    _notification = request.form['NotificationText']

    # Notification is sent to all devices subscribed to topic "ALL" using pyfcm
    result = push_service.notify_topic_subscribers(topic_name="ALL",
                                                   message_body=_notification)

    # return the rendered sent.html with the variable _notification
    return render_template('sent.html', NotificationText=_notification)


if (__name__ == "__main__"):
    app.run()