Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Created July 3, 2024 13:28
Show Gist options
  • Save me-suzy/aa4b96e71ad92108ccf0417473ab69a5 to your computer and use it in GitHub Desktop.
Save me-suzy/aa4b96e71ad92108ccf0417473ab69a5 to your computer and use it in GitHub Desktop.
extradge data si afiseaza in json
import os
import re
import json
# Specifică calea către folderul cu fișierele HTML
folder_path = r'e:\Carte\BB\17 - Site Leadership\Principal 2022\en'
# Lista fișierelor HTML de procesat
html_files = [
'leadership-and-attitude.html','leadership-magic.html','successful-leadership.html','hr-human-resources.html','leadership-laws.html','total-leadership.html','leadership-that-lasts.html','leadership-principles.html','leadership-plus.html','qualities-of-a-leader.html','top-leadership.html','leadership-impact.html','personal-development.html','leadership-skills-and-abilities.html','real-leadership.html','basic-leadership.html','leadership-360.html','leadership-pro.html','leadership-expert.html','leadership-know-how.html','leadership-journal.html','alpha-leadership.html','leadership-on-off.html','leadership-deluxe.html','leadership-xxl.html','leadership-50-extra.html','leadership-fusion.html','leadership-v8.html','leadership-x3-silver.html','leadership-q2-sensitive.html','leadership-t7-hybrid.html','leadership-n6-celsius.html','leadership-s4-quartz.html','leadership-gt-accent.html','leadership-fx-intensive.html','leadership-iq-light.html','leadership-7th-edition.html','leadership-xs-analytics.html','leadership-z3-extended.html','leadership-ex-elite.html','leadership-w3-integra.html','leadership-sx-experience.html','leadership-y5-superzoom.html','performance-ex-flash.html','leadership-mindware.html','leadership-r2-premiere.html','leadership-y4-titanium.html','leadership-quantum-xx.html','python-scripts-examples.html'
]
# Construiește o listă pentru a stoca rezultatele
results = []
# Iterează prin fiecare fișier HTML
for html_file in html_files:
html_file_path = os.path.join(folder_path, html_file)
# Verifică dacă fișierul există în folder
if os.path.isfile(html_file_path):
# Deschide și citește conținutul fișierului HTML
with open(html_file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
# Extrage conținutul dintre <!-- ARTICOL START --> și <!-- ARTICOL FINAL -->
article_content = re.findall(r'<!-- ARTICOL START -->([\s\S]*?)<!-- ARTICOL FINAL -->', html_content)
if article_content:
# Calculează numărul de linii care conțin ">by Neculai Fantanaru</a>"
line_count = sum(1 for line in article_content[0].split('\n') if '>by Neculai Fantanaru</a>' in line)
# Adaugă numele fișierului HTML și numărul de linii în listă
results.append({"html_file": html_file, "line_count": line_count})
# Salvează rezultatul în fișierul categorii.json
output_file_path = os.path.join(folder_path, 'categorii.json') # gasesti fisierul json in e:\Carte\BB\17 - Site Leadership\Principal 2022\en
with open(output_file_path, 'w', encoding='utf-8') as json_file:
json.dump(results, json_file, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment