Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- # Directorul unde se află fișierele HTML
- directory = r'e:\output'
- # Valoarea inițială a lui item_id
- start_id = 6730
- # Pattern-ul regex pentru identificarea liniei cu $item_id
- pattern = re.compile(r'<!-- \$item_id = (\d+); // Replace that with your rating id -->')
- # Obține lista de fișiere HTML din director
- html_files = [f for f in os.listdir(directory) if f.endswith('.html')]
- # Sortează fișierele pentru a se asigura că incrementul se face în ordinea corectă
- html_files.sort()
- # Incrementează și actualizează valoarea lui $item_id în fiecare fișier
- for i, filename in enumerate(html_files):
- file_path = os.path.join(directory, filename)
- with open(file_path, 'r', encoding='utf-8') as file:
- content = file.read()
- match = pattern.search(content)
- if match:
- old_id = int(match.group(1))
- new_id = start_id + i
- new_content = pattern.sub(f'<!-- $item_id = {new_id}; // Replace that with your rating id -->', content)
- with open(file_path, 'w', encoding='utf-8') as file:
- file.write(new_content)
- print(f'Updated {filename} with $item_id = {new_id}')
- else:
- print(f'No match found in {filename}')
- print("All files have been updated successfully.")
Advertisement
Add Comment
Please, Sign In to add comment