💾 Archived View for yretek.com › articulos › 2021 › 12 › text.py captured on 2024-03-21 at 15:49:03.

View Raw

More Information

-=-=-=-=-=-=-

from os import listdir
from os.path import isfile, join

files = sorted([f for f in listdir(".") if isfile(join(".", f))])
files = [x for x in files if x.endswith(".gmi")]

indice = ""
text_to_save = ""

for filename in files:
  filename_date, _ , _ = filename.partition("_")
  text_to_save += "\n\n\n\n* Fecha: " + filename_date
  
  with open(filename, 'r') as reader:
    text_to_save += "\n\n" 
    for line in reader.readlines():
      indice += ("* " +  filename_date + line[1:] ) if line.startswith("# ") else ""
      text_to_save += line
  
   
print(indice+text_to_save)