Skip to content

Instantly share code, notes, and snippets.

@seychelles111
Created April 18, 2023 10:45
Show Gist options
  • Save seychelles111/618a8b1aa0b77ab1289543a883811d18 to your computer and use it in GitHub Desktop.
Save seychelles111/618a8b1aa0b77ab1289543a883811d18 to your computer and use it in GitHub Desktop.
file_content = str()
def bluhbluh(file_name_str):
with open(file_name_str, "r") as f:
exported_str = f.read()
return exported_str
grand_total_ctl_files = glob.glob("*.ctl")
with ThreadPoolExecutor(max_workers=100) as e:### כ-100 threads
all_files_data = list(e.map(bluhbluh, grand_total_ctl_files))
for __unit_data in all_files_data:
file_content += __unit_data
content = file_content
##################################
table_blocks = content.split("INTO TABLE")[1:]
result = {}
for table_block in table_blocks:
table_match = re.search(r"(\w+\.\w+)", table_block)
if table_match:
table_name = table_match.group(1)
fields = re.findall(r"((^,)|\()\s+?(\w+)", table_block, re.MULTILINE)
fields = [field[2].strip() for field in fields] # Extract the third element from each tuple/{REGEXmatch..} in the list
result[table_name] = fields
tables = []
for table_name, fields in result.items():
table = {
"name": table_name,
"fields": fields
}
tables.append(table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment