def post(self) -> None: try: data = json.loads(self.request.body.decode()) except Exception as e: return self.answer(f'Could not upload json {e}', error=True) content = data.get('data', None) if content is None: return self.answer(f'No CSV content', error=True) sync = synchronizer.CSVSynchronizer(self.db) sync_fns: Dict[str, Callable[..., int]] = { 'user': sync.sync_users_from_csv, 'icu': sync.sync_icus_from_csv, 'bedcounts': sync.sync_bedcounts_from_csv } objtype = data.get('objtype', None) sync_fn = sync_fns.get(objtype, None) if sync_fn is None: return self.answer( 'Cannot find proper synchronization method.', error=True ) try: num_updates = sync_fn(io.StringIO(content), force_update=True) return self.answer(f'Updated {num_updates} {objtype}') except: return self.answer('Failing while syncing csv content', error=True)
def post(self) -> None: try: data = json.loads(self.request.body.decode()) except Exception as e: return self.answer(f'Could not upload json {e}', error=True) content = data.get('data', None) if content is None: return self.answer('No CSV content', error=True) sync = synchronizer.CSVSynchronizer(self.db) sync_fns: Dict[base.ObjType, Callable[..., int]] = { base.ObjType.USERS: sync.sync_users_from_csv, base.ObjType.ICUS: sync.sync_icus_from_csv, base.ObjType.BEDCOUNTS: sync.sync_bedcounts_from_csv } objtype_name = data.get('objtype', None) try: objtype = base.ObjType[objtype_name] sync_fn = sync_fns[objtype] except KeyError: return self.answer( 'Cannot find proper synchronization method.', error=True ) try: num_updates = sync_fn(io.StringIO(content), force_update=True) return self.answer(f'Updated {num_updates} {objtype}') except Exception as e: return self.answer(f'Failing while syncing csv content: {e}', error=True)
def main(args=None): cfg = config.Config(FLAGS.config, mode=FLAGS.mode, env_path=FLAGS.dotenv_path) store_factory = db_store.create_store_factory_for_sqlite_db(cfg) store = store_factory.create() csv_synchronizer = synchronizer.CSVSynchronizer(store) add_pre_icubam_bed_counts(FLAGS.pre_icubam_data_path, csv_synchronizer)
def main(args=None): cfg = config.Config(FLAGS.config, env_path=FLAGS.dotenv_path) store_factory = db_store.create_store_factory_for_sqlite_db(cfg) db = store_factory.create() csv = synchronizer.CSVSynchronizer(db) out_buf = csv.export_icus() if FLAGS.output: with open(FLAGS.output, 'w') as f_out: f_out.write(out_buf) else: print(out_buf)
def main(args=None): cfg = config.Config(FLAGS.config, env_path=FLAGS.dotenv_path) store_factory = db_store.create_store_factory_for_sqlite_db(cfg) store = store_factory.create() csv = synchronizer.CSVSynchronizer(store) if FLAGS.icus_csv: print(f"Loading ICU CSV from: {FLAGS.icus_csv}") with open(FLAGS.icus_csv) as icus_f: csv.sync_icus_from_csv(icus_f, FLAGS.force_update) if FLAGS.users_csv: print(f"Loading user CSV from: {FLAGS.users_csv}") with open(FLAGS.users_csv) as users_f: csv.sync_users_from_csv(users_f, FLAGS.force_update) if FLAGS.bedcounts_csv: print(f"Loading bedcounts CSV from: {FLAGS.bedcounts_csv}") with open(FLAGS.bedcounts_csv) as bedcounts_f: csv.sync_bedcounts_from_csv(bedcounts_f, FLAGS.force_update)
def setUp(self): store_factory = store.StoreFactory( sqla.create_engine("sqlite:///:memory:", echo=True)) self.db = store_factory.create() self.csv = synchronizer.CSVSynchronizer(self.db)