#!/usr/bin/env python3
import re

def filter_myanmar(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as f:
        lines = f.readlines()
    
    filtered = []
    prev_line = None
    for line in lines:
        stripped = line.rstrip('\n')
        # Skip lines containing Vietnamese translation arrow
        if '→' in stripped:
            continue
        # Keep all other lines (including blank lines)
        # But we need to deduplicate consecutive identical page markers
        # Detect page marker: starts with optional [, then TRANG, then space, then digits, then optional ]
        if re.match(r'^\[?TRANG\s+\d+\]?$', stripped.strip()):
            if prev_line is not None and prev_line == stripped:
                # Skip duplicate consecutive page marker
                continue
        filtered.append(stripped)
        prev_line = stripped
    
    with open(output_file, 'w', encoding='utf-8') as f:
        f.write('\n'.join(filtered))

if __name__ == '__main__':
    filter_myanmar('Tam Bao.txt', 'Tam Bao - Myanmar.txt')
    print("Filtered file saved as 'Tam Bao - Myanmar.txt'")