示例#1
0
def register_push_token():
    token = util.args()['push_token']
    platform_type = util.args()['type']
    entry = db.push_tokens.find_one({"token": token, "type": platform_type})
    if entry == None:
        entry = {"token": token, "type": platform_type}
    entry['phone'] = util.myphone()
    db.push_tokens.save(entry)
    return json.dumps({"success": True})
示例#2
0
def which_users_not_signed_up():
    users_signed_up = map(
        lambda user: user['phone'],
        db.users.find({"phone": {
            "$in": util.args()['phones']
        }}))
    users_not_signed_up = [
        phone for phone in util.args()['phones']
        if phone not in users_signed_up
    ]
    return json.dumps({
        "success": True,
        "users_not_signed_up": users_not_signed_up
    })
示例#3
0
 def test_common_options_works_with_all_required_args(self):
     with output_to_string():
         with args('--host=foo'):
             try:
                 MockCommand().run()
             except SystemExit:
                 self.fail('Should not have exited with all required args')
示例#4
0
def send_squawk():
    sender = myphone()
    util.log("sent squawk from %s to %s" %
             (sender, ' '.join(args()['recipients'])))
    if args()['recipients'] == [robot.ROBOT_PHONE]:
        robot.send_robot_message(sender)
    if sender:
        duration = args().get('duration', -1)
        data = flask.request.data
        filename = s3.generate_unique_filename_with_ext('m4a')
        audio_url = s3.upload_file(filename, data)
        success = deliver_squawk(args()['recipients'], sender, audio_url,
                                 duration)
        return json.dumps({"success": success})
    else:
        return json.dumps({"success": False, "error": "bad_token"})
示例#5
0
def listened():
    id = ObjectId(args()['id'])
    msg = db.messages.find_one({'_id': id})
    if msg:
        msg['listened'] = True
        db.messages.save(msg)
    return json.dumps({"success": msg != None})
示例#6
0
 def test_common_options_works_with_all_required_args(self):
     with output_to_string():
         with args('--host=foo'):
             try:
                 MockCommand().run()
             except SystemExit:
                 self.fail('Should not have exited with all required args')
示例#7
0
def make_token():
	secret = args()['secret']
	matching_user = db.users.find_one({'secret': secret})
	if matching_user:
		phone = matching_user['phone']
		token = generate_token(phone)
		db.tokens.save({"phone": phone, "token": token})
		return json.dumps({"success": True, "token": token, "phone": phone})
	else:
		return json.dumps({"success": False, "error": "bad_login"})
示例#8
0
def send_checkmark():
    # calling this endpoint with GET is deprecated!
    recipients = util.args()['recipients'] if 'recipients' in util.args(
    ) else [util.args()['recipient']]
    sender = util.myphone()
    thread_identifier = util.args().get('thread_identifier', '')
    pushes = []
    for recipient in set(recipients):
        if not push.should_send_push_to_user_for_thread(
                recipient, thread_identifier):
            continue
        name = squawk.name_for_user(sender, recipient)
        message = u"%s: ✓" % (name)
        for token_info in db.push_tokens.find({"phone": recipient}):
            pushes.append(
                push.Push(recipient, token_info['type'], token_info['token'],
                          message, "", {"type": "checkmark"}))
    push.send_pushes(pushes)
    return json.dumps({"success": True})
示例#9
0
def serve_squawk():
    phone = myphone()
    id = args()['id']
    msg = db.messages.find_one({
        "recipient": phone,
        "_id": bson.objectid.ObjectId(id)
    })
    if msg:
        return flask.redirect(msg.get('audio_url', ''))
    else:
        flask.abort(403)
示例#10
0
 def test_host_required(self):
     with output_to_string():
         with args():
             self.assertRaises(SystemExit, MockCommand)
示例#11
0
 def test_host_required(self):
     with output_to_string():
         with args():
             self.assertRaises(SystemExit, MockCommand)
示例#12
0
def unregister_push_token():
    token = util.args()['push_token']
    platform_type = util.args()['type']
    db.push_tokens.remove({"token": token, "type": platform_type})
                    type=int,
                    help='Intervene from this specific round')
parser.add_argument('-pnoise',
                    default=1.0,
                    type=float,
                    help="""Percentage of random noise.
                    1 means complete noise""")
opt = parser.parse_args()

# Load checkpoint
print("=> loading checkpoint '{}'".format(opt.save_model))
checkpoint = torch.load(opt.save_model)

# Merge two argparse namespaces with priority to args from this script
opt = {**vars(checkpoint['opt']), **vars(opt)}
opt = args(opt)  # wrapper around a dict to object with fields

print(opt.__dict__)

print("=> loaded checkpoint '{}'".format(opt.save_model))

# Construct dataloader
loader = DataLoader(opt, ['val'])
vocab_size = loader.vocab_size
opt.vocab_size = vocab_size
bos_idx = loader.data['word2ind']['<START>']
eos_idx = loader.data['word2ind']['<EOS>']

# Load models
qbot = models.QBot(opt)
abot = models.ABot(opt)