ro  fr  en  es  pt  ar  zh  hi  de  ru
ART 2.0 ART 3.0 ART 4.0 ART 5.0 ART 6.0 Pinterest

Python: Mitadiava ireo rakitra rehetra izay misy teny roa (kofehy na isa)

On February 28, 2022, in Leadership Quantum-XX, by Neculai Fantanaru

Azonao atao ny mijery ny kaody feno:Https: // passatin.com / pk42 wg

hametrakaPython. Inona no ataon'ilay kaody eto?

Ao amin'ny rakitra HTML tsirairay dia manana sequence php misy ity variana ity aho$ item_id = isa;

iray.dia mitovy amin'ny 1 ka hatramin'ny 1600 (na hatramin'ny isa izay tianao) ohatra amin'ny rakitra iray$ item_id =HTML novokarina tamin'ny fampiasana hilite.metelo amby roapolo;ary amin'ny rakitra hafa azoko$ item_id = 1340;Sy ny sisa..

Te-hahita ireo rakitra ireo izay misy ny isa ao amin'ny kofehy miverimberina. Ohatra, afaka manana aho$ item_id =HTML novokarina tamin'ny fampiasana hilite.metelo amby roapolo;n rakitra ary afaka mitovy$ item_id =HTML novokarina tamin'ny fampiasana hilite.metelo amby roapolo;amin'ny rakitra hafa. Ny kaody python dia hamonjyvaliny_duplicates.txtNy anarana rakitra rehetra izay misy dikanteny amin'ity karazana ity.

Codul: mandika sy mitantana ny kaody eto ambany amin'ny programa mpandika teny (ampiasaiko pycripter.

Ny kaody:

import os
import re

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'))


def get_duplicates(directory_path, results_file):
    duplicates = dict()
    fisiere_care_nu_au_id = ''
    fisiere_duplicat = ''
    id_pattern = re.compile('\$item_id = (.*?);')
    for f in os.listdir(directory_path):
            if f.endswith('.html') and f != 'termeni-si-conditii.html' and f != "parteneri.html":
                filepath = directory_path + '//' + f
                file_text = read_text_from_file(filepath)
                number = re.findall(id_pattern, file_text)
                if len(number) != 0:
                    number = number[0]
                    number = number.strip()
                    if number in duplicates.keys():
                        duplicates[number].append(f)
                        # duplicates[number].append(f)
                    else:
                        duplicates[number] = [f]
                else:
                    fisiere_care_nu_au_id = fisiere_care_nu_au_id + f + '\n'

    for key in duplicates.keys():
        if len(duplicates[key]) >= 2:
            print(key)
            for f in duplicates[key]:
                fisiere_duplicat = fisiere_duplicat + f + '\n'
            fisiere_duplicat += '\n\n'

    result = "FISIERE CARE NU AU ID \n\n" + fisiere_care_nu_au_id + '\n' + "FISIERE DUPLICAT \n\n" + fisiere_duplicat
    write_to_file(result, results_file)

    print("Scriere efectuata cu succes.")

if __name__ == '__main__':
    directory_path = "e:\\Carte\\BB\\17 - Site Leadership\\Principal\\ro"
    results_file = "e:\\Carte\\BB\\17 - Site Leadership\\Principal\\ro\\results_duplicates.txt"
    get_duplicates(directory_path, results_file)

That's all folks.

If you like my code, then make me a favor: translate your website into Romanian, "ro".

Ary koa, misyVersion 2amin'ity code ity naVersion 3naVersion 4naVersion 5

 


Latest articles accessed by readers:

  1. An Eye To See And A Mind To Understand
  2. Turn Towards Me With An Eye Full Of Your Own Gaze
  3. The Snapshot Of Magic In God's Universe
  4. Rhythm Of My Heart

Donate via Paypal

Alternate Text

RECURRENT DONATION

Donate monthly to support
the NeculaiFantanaru.com project

SINGLE DONATION

Donate the desired amount to support
the NeculaiFantanaru.com project

Donate by Bank Transfer

Account Ron: RO34INGB0000999900448439

Open account at ING Bank

Join The Neculai Fantanaru Community



* Note: If you want to read all my articles in real time, please check the romanian version !

decoration
About | Site Map | Partners | Feedback | Terms & Conditions | Privacy | RSS Feeds
© Neculai Fântânaru - All rights reserved