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)
            ), "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)
        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)
示例#4
0
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("-e", "--user_email", nargs="+")
    group.add_argument("-u", "--user_uuid", nargs="+")

    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]
    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)
示例#5
0
    
    msg = parser.add_mutually_exclusive_group(required=True)
    msg.add_argument("-t", "--title_message", nargs=2,
        help="specify title and message, in that order")
    msg.add_argument("-s", "--silent", action="store_true",
        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="+")
   
    parser.add_argument("-d", "--dev", action="store_true", default=False)

    args = parser.parse_args()

    if args.user_uuid:
        uuid_list = map(lambda uuid_str: uuid.UUID(uuid_str), args.user_uuid)
    else:
        uuid_list = map(lambda uuid_str: ecwu.User.fromEmail(uuid_str).uuid, 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:
        response = pnu.send_visible_notification_to_users(uuid_list,
                                                            args.title_message[0],
                                                            args.title_message[1],
                                                            {},
                                                            dev = args.dev)
    pnu.display_response(response)
        "--silent",
        action="store_true",
        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="+")

    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]
    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:
        response = pnu.send_visible_notification_to_users(
            uuid_list,
            args.title_message[0],
            args.title_message[1], {},
            dev=args.dev)
    pnu.display_response(response)
示例#7
0
        help="a specification for the survey that can potentially include targeting information")

    args = parser.parse_args()

    survey_spec = json.load(open(args.survey_spec))
    assert (survey_spec["alert_type"] == "survey" or survey_spec["alert_type"] == "notify"), "alert_type = %s, expected 'survey' or 'notify'" % survey_spec["alert_type"]

    if args.user_uuid:
        uuid_list = [uuid.UUID(uuid_str) for uuid_str in args.user_uuid]
    elif args.user_email:
        uuid_list = [ecwu.User.fromEmail(uuid_str).uuid for uuid_str in 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)