def push_to_user(uuid_list, message):
    logging.debug("About to send notifications to: %s users" % len(uuid_list))
    json_data = {
        "title": "GreenTrip Notification",
        "message": message
    }
    logging.debug(uuid_list)
    response = pnu.send_visible_notification_to_users(uuid_list,
                                                        json_data["title"],
                                                        json_data["message"],
                                                        json_data,
                                                        dev = False)
    pnu.display_response(response)
Пример #2
0
            ), "alert_type = %s, expected 'survey' or 'notify'" % survey_spec[
                "alert_type"]

    if args.user_uuid:
        uuid_list = map(lambda uuid_str: uuid.UUID(uuid_str), args.user_uuid)
    elif args.user_email:
        uuid_list = map(lambda uuid_str: ecwu.User.fromEmail(uuid_str).uuid,
                        args.user_email)
    else:
        assert args.query_spec is not None
        uuid_list = get_uuid_list_from_spec(args.query_spec)

    logging.info("About to push to uuid list = %s" % uuid_list)

    if args.show_emails:
        logging.info("About to push to email list = %s" % [
            ecwu.User.fromUUID(uuid)._User__email
            for uuid in uuid_list if uuid is not None
        ])

    if args.dry_run:
        logging.info("dry run, skipping actual push")
    else:
        response = pnu.send_visible_notification_to_users(
            uuid_list,
            survey_spec["title"],
            survey_spec["message"],
            survey_spec,
            dev=args.dev)
        pnu.display_response(response)
Пример #3
0
        help="send a silent push notification. title and message are ignored")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("-e", "--user_email", nargs="+")
    group.add_argument("-u", "--user_uuid", nargs="+")
    group.add_argument("-a", "--all", action="store_true") 
    parser.add_argument("-d", "--dev", action="store_true", default=False)

    args = parser.parse_args()

    if args.user_uuid:
        uuid_list = [uuid.UUID(uuid_str) for uuid_str in args.user_uuid]
    if args.all:
        uuid_list = esdu.get_all_uuids() 
    else:
        uuid_list = [ecwu.User.fromEmail(uuid_str).uuid for uuid_str in args.user_email]
    logging.info("After parsing, uuid list = %s" % uuid_list)

    if (args.silent):
        response = pnu.send_silent_notification_to_users(uuid_list, {}, dev=args.dev)
    else:
        json_data = {
            "title": args.title_message[0],
            "message": args.title_message[1]
        }
        response = pnu.send_visible_notification_to_users(uuid_list,
                                                            json_data["title"],
                                                            json_data["message"],
                                                            json_data,
                                                            dev = args.dev)
    pnu.display_response(response)