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})
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 })
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')
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"})
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})
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"})
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})
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)
def test_host_required(self): with output_to_string(): with args(): self.assertRaises(SystemExit, MockCommand)
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)