Skip to content

Commit

Permalink
Create atf2conc.py
Browse files Browse the repository at this point in the history
  • Loading branch information
epageperron authored May 24, 2023
1 parent 2f82f04 commit cabf93f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions atf2conc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re

def parse_atf(atf_file, output_file):
with open(atf_file, 'r') as file:
lines = file.readlines()

parsed_lines = []
current_text = None
current_surface = None
current_column = None

surfaces = ['obverse', 'reverse', 'left edge', 'right edge', 'bottom edge', 'edge', 'surface a']

for line in lines:
if line.startswith('&'):
# New text
current_text = line.split('=')[0].strip('& ')
current_column = None # Clear the column variable when encountering a new text
elif any(line.startswith(f'@{surface}') for surface in surfaces):
# Set current surface
for surface in surfaces:
if line.startswith(f'@{surface}'):
current_surface = surface
current_column = None # Clear the column variable when changing the surface
break
elif line.startswith('@column'):
# Set current column
current_column = line.split()[1]
elif not line.startswith(('#', '$', '>', '@')):
# Process text lines
cleaned_line = re.sub(r'(\$|\@)[^\s]+', '', line).strip()
if current_text is not None and current_surface is not None and cleaned_line:
if current_column:
parsed_line = f'{current_text} {current_surface} col. {current_column} {cleaned_line}'
else:
parsed_line = f'{current_text} {current_surface} {cleaned_line}'
parsed_lines.append(parsed_line)

with open(output_file, 'w') as file:
file.write('\n'.join(parsed_lines))

# Specify the input ATF file and output file name
atf_file = 'inscriptions.atf'
output_file = 'output.txt'

# Call the function to parse ATF and write to file
parse_atf(atf_file, output_file)

0 comments on commit cabf93f

Please sign in to comment.