def run(path=None): if path is None: private_data_dir = Path("../private-data") xlsx_files = [ f for f in private_data_dir.iterdir() if f.suffix in {".xlsx", ".csv"} ] else: xlsx_files = [Path(path)] print(f"Found {len(xlsx_files)} xlsx files in private-data") for file in xlsx_files: try: print(f"---- Importing {file} ----") import_obj = data_import.smart_import( path=file, uploader_name="Uploaded via CLI", current_as_of=date.today(), overwrite_in_prog=True, ) data_import.finalize_import(import_obj) except ppe.errors.NoMappingForFileError: print(f"{file} does not appear to be a format we recognize") except ppe.errors.PartialFile: print( f"{file} appears to have changed and does not match the format anymore" ) finally: print(f"---- Import of {file} complete ----") print() print()
def retry(self): with tempfile.NamedTemporaryFile( "w+b", delete=False, suffix=self.file_name ) as f: f.write(self.data) f.flush() from ppe.data_import import smart_import, finalize_import import_obj = smart_import( path=Path(f.name), uploader_name=self.uploaded_by.username, current_as_of=self.current_as_of, user_provided_name=self.file_name, overwrite_in_prog=True ) finalize_import(import_obj) self.fixed = True self.save()
def post(self, request, import_id): data_import.finalize_import(DataImport.objects.get(id=import_id)) return HttpResponseRedirect(reverse("index"))