def incoming(backend_name, identity, text): backend = settings.INSTALLED_BACKENDS.get(backend_name, {}) if "HANDLER" in backend: module = try_import(backend['HANDLER']) if module: module.incoming(backend_name, identity, text) else: backend, _ = Backend.objects.get_or_create(name=backend_name) connection, _ = backend.connection_set.get_or_create(identity=identity) message = IncomingMessage(connection, text, datetime.datetime.now()) router = Router() response = router.incoming(message)
def incoming(backend_name, identity, text): backend = settings.INSTALLED_BACKENDS.get(backend_name, {}) if "HANDLER" in backend: module = try_import(backend["HANDLER"]) if module: module.incoming(backend_name, identity, text) else: backend, _ = Backend.objects.get_or_create(name=backend_name) connection, _ = backend.connection_set.get_or_create(identity=identity) message = IncomingMessage(connection, text, datetime.datetime.now()) router = Router() response = router.incoming(message)
def make_fake_message(request, patient_id): """Make up a message for the patient's wisepill device and fake it coming in""" logger.debug('make_fake_message') patient = get_object_or_404(Patient, pk=patient_id) msisdn = patient.wisepill_msisdn if not msisdn: messages.error(request, "Must set patient's MSISDN before we can fake a wisepill message from them") return redirect('patient-list') timestamp = datetime.datetime.now() # 50-50 whether to make a delayed message is_delayed = random.randint(0,99) > 50 if is_delayed: timestamp -= datetime.timedelta(minutes=10) delay_value = "03" if is_delayed else "02" # DDMMYYHHMMSS time_value = timestamp.strftime("%d%m%y%H%M%S") # 50-50 old format or new format new_format = random.randint(0,99) > 50 if new_format: start = "AT={delay_value},".format(**locals()) else: start = "@={delay_value},".format(**locals()) text = start + "CN={msisdn},SN=fake,T={time_value},S=20,B=3800,PC=1,U=fake,M=1,CE=0".format(**locals()) connection = patient.contact.default_connection msg = IncomingMessage(connection=connection, text=text) router = Router() router.incoming(msg) messages.info(request, "Sent fake wisepill message from %s" % patient) return redirect('patient-list')
def make_fake_message(request, patient_id): """Make up a message for the patient's wisepill device and fake it coming in""" logger.debug("make_fake_message") patient = get_object_or_404(Patient, pk=patient_id) msisdn = patient.wisepill_msisdn if not msisdn: messages.error(request, "Must set patient's MSISDN before we can fake a wisepill message from them") return redirect("patient-list") timestamp = datetime.datetime.now() # 50-50 whether to make a delayed message is_delayed = random.randint(0, 99) > 50 if is_delayed: timestamp -= datetime.timedelta(minutes=10) delay_value = "03" if is_delayed else "02" # DDMMYYHHMMSS time_value = timestamp.strftime("%d%m%y%H%M%S") # 50-50 old format or new format new_format = random.randint(0, 99) > 50 if new_format: start = "AT={delay_value},".format(**locals()) else: start = "@={delay_value},".format(**locals()) text = start + "CN={msisdn},SN=fake,T={time_value},S=20,B=3800,PC=1,U=fake,M=1,CE=0".format(**locals()) connection = patient.contact.default_connection msg = IncomingMessage(connection=connection, text=text) router = Router() router.incoming(msg) messages.info(request, "Sent fake wisepill message from %s" % patient) return redirect("patient-list")
def run(self, backend_name, identity, text): backend, _ = Backend.objects.get_or_create(name=backend_name) connection, _ = backend.connection_set.get_or_create(identity=identity) message = IncomingMessage(connection, text, datetime.datetime.now()) router = Router() response = router.incoming(message)