Neculai Fântânaru

Everything Depends On The Leader

Add The First 80 Words Of The Text Section To The Meta Description Html Tag

On August 16, 2022
, in
Python Scripts Examples by Neculai Fantanaru

You can view the entire code here: https://pastebin.com/PLEUKv98

Install Python.

The html tag is given:

<meta name="description" content="Ma numesc Neculai Fantanaru, locuiesc in Iasi.">

And we have the following section of text:

<!-- ARTICOL START -->

<p class="text_obisnuit2">Scopul lorem ipsum este de a crea un bloc de text cu aspect natural
(propoziție, paragraf, pagină) care nu distrage atenția de la aspect. O practică nu lipsită 
de controverse, aranjarea paginilor cu text de umplere fără sens poate fi foarte utilă atunci
când accentul este menit să fie pe design, nu pe conținut. Pasajul a cunoscut o creștere a 
popularității în anii 1960, când Letraset l-a folosit pe foile lor de transfer uscat și, din 
nou, în anii 90, când editorii desktop au inclus textul cu software-ul lor. Astăzi se vede 
peste tot pe web; pe șabloane, site-uri web și modele stoc. Utilizați generatorul nostru 
pentru a obține propriul dvs. sau citiți mai departe pentru istoria autorizată a lui lorem 
ipsum.</p>

<!-- ARTICOL FINAL -->

OUTPUT: After running the code, python will take the first 80 words of the text section and add them to the "meta description" html tag:

<meta name="description" content="Ma numesc Neculai Fantanaru, locuiesc in Iasi. Scopul lorem ipsum este de a crea un bloc de text cu aspect natural (propoziție, paragraf, pagină) care nu distrage atenția de la aspect. O practică nu lipsită de controverse, aranjarea paginilor cu text de umplere fără sens poate fi foarte utilă atunci când accentul este menit să fie pe design, nu pe conținut. Pasajul a cunoscut o creștere a popularității în anii 1960, când Letraset l-a folosit pe foile lor de transfer uscat și, din">

I also made a dictionary that automatically transforms diacritics when words are moved from one side to another:

import requests
import re
import os

cale_folder_html = r"d:\\Folder1\\fisiere_html_modificate"
extension_file = ".html"

def read_text_from_file(file_path):
    """
    Aceasta functie returneaza continutul unui fisier.
    file_path: calea catre fisierul din care vrei sa citesti
    """
    with open(file_path, encoding='utf8') as f:
        text = f.read()
        return text


def write_to_file(text, file_path):
    """
    Aceasta functie scrie un text intr-un fisier.
    text: textul pe care vrei sa il scrii
    file_path: calea catre fisierul in care vrei sa scrii
    """
    with open(file_path, 'wb') as f:
        f.write(text.encode('utf8', 'ignore'))


print('Going through folder')
amount = 1

# prelucrare continut
dict_simboluri = dict()
dict_simboluri['&#259;'] = 'a'
dict_simboluri['&#226;'] = 'a'
dict_simboluri['&atilde;'] = 'a'
dict_simboluri['&acirc;'] = 'a'
dict_simboluri['&#x103;'] = 'a'
dict_simboluri['&#xE2;'] = 'a'
dict_simboluri['?'] = 'a'
dict_simboluri['?'] = 'a'
dict_simboluri['â'] = 'a'
dict_simboluri['a'] = 'a'
dict_simboluri['ã'] = 'a'
dict_simboluri['à'] = 'a'
dict_simboluri['á'] = 'a'
dict_simboluri['Ã¥'] = 'a'
dict_simboluri['ä'] = 'a'
dict_simboluri['â'] = 'a'

dict_simboluri['&hellip;'] = ''
dict_simboluri['&#8230;'] = ''
dict_simboluri['\&quot;'] = ''
dict_simboluri['&#8211;'] = '- '
dict_simboluri['  '] = ' '
dict_simboluri['Â '] = ' '
dict_simboluri['Â '] = ' '
dict_simboluri['&#039;'] = '\''
dict_simboluri['"'] = '\''
dict_simboluri['"'] = '\''
dict_simboluri['['] = ''
dict_simboluri[']'] = ''
dict_simboluri['/'] = ''
dict_simboluri['}'] = ''
dict_simboluri['{'] = ''

dict_simboluri['&icirc;'] = 'i'
dict_simboluri['&#206;'] = 'i'
dict_simboluri['&#238;'] = 'i'
dict_simboluri['&#xEE;'] = 'i'
dict_simboluri['&#xCE;'] = 'i'
dict_simboluri['&#206;'] = 'i'
dict_simboluri['&#xEE;'] = 'i'
dict_simboluri['&#xCE;'] = 'i'
dict_simboluri['?'] = 'i'
dict_simboluri['î'] = 'i'
dict_simboluri['&Icirc;'] = 'I'
dict_simboluri['I'] = 'I'
dict_simboluri['Ã"¨'] = 'I'
dict_simboluri['ÃŽ'] = 'I'
dict_simboluri['ÃŽ'] = 'I'
dict_simboluri['i'] = 'i'
dict_simboluri['i'] = 'i'
dict_simboluri['í'] = 'i'
dict_simboluri['!'] = ' '
dict_simboluri['('] = '-'
dict_simboluri[')'] = ' '
dict_simboluri['  '] = ' '
dict_simboluri[',,'] = ' '
dict_simboluri['I'] = 'I'
dict_simboluri['é'] = 'e'
dict_simboluri['ê'] = 'e'
dict_simboluri['é'] = 'e'
dict_simboluri['a©'] = 'e'
dict_simboluri['è'] = 'e'
dict_simboluri['ë'] = 'e'
dict_simboluri['Ë'] = 'e'


dict_simboluri['&#537;'] = 's'
dict_simboluri['&#536;'] = 's'
dict_simboluri['&#350;'] = 's'
dict_simboluri['&#x219;'] = 's'
dict_simboluri['&#351;'] = 's'
dict_simboluri['s'] = 's'
dict_simboluri['?'] = 's'
dict_simboluri['S'] = 'S'
dict_simboluri['?'] = 'S'
dict_simboluri['?'] = 'S'
dict_simboluri['Å¡'] = 's'
dict_simboluri['s'] = 's'
dict_simboluri['?'] = 's'
dict_simboluri['?'] = 's'

dict_simboluri['&quot;'] = ''
dict_simboluri['&#8217;'] = ''
dict_simboluri['&rdquo;'] = ''
dict_simboluri['&rsquo;'] = ''
dict_simboluri['&bdquo;'] = ''
dict_simboluri['&ldquo;'] = ''
dict_simboluri['&#8222;'] = ''
dict_simboluri['&#8220;'] = ''
dict_simboluri['&#8221;'] = ''
dict_simboluri['&lt;'] = ''
dict_simboluri['&lt;'] = ''
dict_simboluri['«'] = ''
dict_simboluri['»'] = ''
dict_simboluri['"'] = ''
dict_simboluri['"'] = ''
dict_simboluri['"'] = ''
dict_simboluri[':'] = ''
dict_simboluri['&amp;'] = ''

dict_simboluri['&#539;'] = 't'
dict_simboluri['&#355;'] = 't'
dict_simboluri['&#354;'] = 't'
dict_simboluri['&#x21B;'] = 't'
dict_simboluri['t'] = 't'
dict_simboluri['?'] = 't'
dict_simboluri['T'] = 'T'
dict_simboluri['?'] = 'T'
dict_simboluri['t'] = 't'
dict_simboluri['?'] = 't'

for filename in os.listdir(cale_folder_html):
        if filename == 'y_key_e479323ce281e459.html' or filename == 'directory.html':
            continue
        if filename.endswith('.html'):
            cale_fisier_html = cale_folder_html + "\\" + filename
            html_text = read_text_from_file(cale_fisier_html)
            articol_pattern = re.compile('<!-- ARTICOL START -->([\s\S]*?)<!-- ARTICOL FINAL -->[\s\S]*?')
            articol_text = re.findall(articol_pattern, html_text)

            if len(articol_text) > 0:
                articol_text = articol_text[0]
                meta_description = re.search('<meta name="description".+>', html_text)[0]
                initial_meta_description = re.search('<meta name="description" content="(.+)".*>', html_text)[1]
                para_pattern = re.compile('<p.+>(.*?)</p>')
                para = re.findall(para_pattern, articol_text)
                if len(para) > 0:
                    lista_cuvinte = list()
                    for txt in para:
                        for simbol in dict_simboluri.keys():
                            txt = txt.replace(simbol, dict_simboluri[simbol])
                        lista_cuvinte.extend(re.findall(r'[a-zA-Z\-\']+', txt))

                    content = " ".join(lista_cuvinte[:80])

                    new_meta_description = re.sub(r'content=".+"', f'content="{content}"', meta_description)
                    html_text = html_text.replace(meta_description, new_meta_description)

                    print(f'{filename} parsed ({amount})')
                    amount += 1
                    write_to_file(html_text, cale_fisier_html)

                else:
                    print("Nu am gasit tag-uri cu text_obisnuit2: ", filename)
                    continue
            else:
                print("Nu are ARTICOL START/FINAL: ", filename)
                continue
        else:
            continue

That's all folks.

Also, see this VERSION 2 or VERSION 3 or VERSION 4 or VERSION 5 or VERSION 6 or VERSION 7

Alatura-te Comunitatii Neculai Fantanaru
The 63 Greatest Qualities of a Leader
Cele 63 de calităţi ale liderului

Why read this book? Because it is critical to optimizing your performance. Because it reveals the main coordinates after that are build the character and skills of the leaders, highlighting what it is important for them to increase their influence.

Leadership - Magic of Mastery
Atingerea maestrului

The essential characteristic of this book in comparison with others on the market in the same domain is that it describes through examples the ideal competences of a leader. I never claimed that it's easy to become a good leader, but if people will...

The Master Touch
Leadership - Magia măiestriei

For some leaders, "leading" resembles more to a chess game, a game of cleverness and perspicacity; for others it means a game of chance, a game they think they can win every time risking and betting everything on a single card.

Leadership Puzzle
Leadership Puzzle

I wrote this book that conjoins in a simple way personal development with leadership, just like a puzzle, where you have to match all the given pieces in order to recompose the general image.

Performance in Leading
Leadership - Pe înţelesul tuturor

The aim of this book is to offer you information through concrete examples and to show you how to obtain the capacity to make others see things from the same angle as you.

Leadership for Dummies
Leadership - Pe înţelesul tuturor

Without considering it a concord, the book is representing the try of an ordinary man - the author - who through simple words, facts and usual examples instills to the ordinary man courage and optimism in his own quest to be his own master and who knows... maybe even a leader.