Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Created February 27, 2026 03:53
Show Gist options
  • Select an option

  • Save me-suzy/d54a1ebff799d08ebb6a861d5dd552a3 to your computer and use it in GitHub Desktop.

Select an option

Save me-suzy/d54a1ebff799d08ebb6a861d5dd552a3 to your computer and use it in GitHub Desktop.
Replace afas.py
import os
import re
import sys
def process_file(filepath):
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
if '<!-- SASA-2 -->' in content:
return False # already has it
if '<!-- ARTICOL FINAL -->' not in content:
return False # no anchor
# Pattern: </p> followed by </div> (with optional whitespace/lines between)
# followed by optional <p...>...</p> and <!-- ARTICOL FINAL -->
pattern = r'(</p>)\s*(</div>)\s*(?:<p[^<]*?</p>\s*)?(<!-- ARTICOL FINAL -->)'
replacement = r'\1\n\n<!-- SASA-2 -->\n\2\n\n\3'
new_content, count = re.subn(pattern, replacement, content, flags=re.DOTALL)
if count > 0:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
return True
return False
def main():
folder = input("Introdu calea folderului cu fisiere HTML: ").strip()
if not os.path.isdir(folder):
print(f"Folderul '{folder}' nu exista.")
return
modified = 0
skipped = 0
not_found = 0
for root, dirs, files in os.walk(folder):
for fname in files:
if fname.lower().endswith(('.html', '.htm', '.php')):
fpath = os.path.join(root, fname)
result = process_file(fpath)
if result:
modified += 1
print(f" MODIFICAT: {fpath}")
elif '<!-- SASA-2 -->' in open(fpath, 'r', encoding='utf-8', errors='ignore').read():
skipped += 1
else:
not_found += 1
print(f" PATTERN NEGASIT: {fpath}")
print(f"\nRezultat: {modified} modificate, {skipped} aveau deja SASA-2, {not_found} fara pattern")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment