def create_resources(file, skip_lines): """Creates resources for the script or errors out if not possible""" engine = Engine() table = engine.auto_create_table(Table(str(file), header_rows=skip_lines), filename=file, make=False) clean_table = table.__dict__ resource_dict = {} path_to_table = os.path.basename(clean_table["name"]) resource_dict["name"] = os.path.splitext(path_to_table)[0] resource_dict["schema"] = {} resource_dict["dialect"] = {} resource_dict["schema"]["fields"] = [] for cname, ctuple in clean_table["columns"]: resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0] }) resource_dict["url"] = "FILL" return resource_dict
def create_tabular_resources(self, file, skip_lines, encoding): """Create resources for tabular scripts""" engine = Engine() self.encoding = encoding engine.encoding = encoding table_val = Table(str(file), header_rows=skip_lines) table = engine.auto_create_table(table_val, filename=file, make=False) clean_table = table.__dict__ resource_dict = {} path_to_table = os.path.basename(clean_table["name"]) print("Processing... {file_name}".format(file_name=path_to_table)) r_name = os.path.splitext(path_to_table)[0].lower() resource_dict["name"] = clean_table_name(r_name) resource_dict["path"] = path_to_table resource_dict["schema"] = {} resource_dict["dialect"] = {"delimiter": ","} resource_dict["schema"]["fields"] = [] for cname, ctuple in clean_table["columns"]: if len(ctuple) >= 2: if ctuple[0] == "char": # char sizes need quotes char_size = "{a}".format(a=ctuple[1]) resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0], "size": char_size }) else: resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0], "size": ctuple[1] }) else: resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0] }) resource_dict["url"] = "fill" return resource_dict
def create_resources(file, skip_lines): """Creates resources for the script or errors out if not possible""" engine = Engine() table = engine.auto_create_table(Table(str(file), header_rows=skip_lines), filename=file, make=False) clean_table = table.__dict__ resource_dict = {} path_to_table = os.path.basename(clean_table["name"]) print("Processing... {file_name}".format(file_name=path_to_table)) resource_dict["name"] = os.path.splitext(path_to_table)[0].lower() resource_dict["path"] = path_to_table resource_dict["schema"] = {} resource_dict["dialect"] = {"delimiter": ","} resource_dict["schema"]["fields"] = [] for cname, ctuple in clean_table["columns"]: if len(ctuple) >= 2: if ctuple[0] == 'char': # char sizes need quotes char_size = "{a}".format(a=ctuple[1]) resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0], "size": char_size }) else: resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0], "size": ctuple[1] }) else: resource_dict["schema"]["fields"].append({ "name": cname, "type": ctuple[0] }) resource_dict["url"] = "FILL" return resource_dict