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

पायथन: उन सभी फ़ाइलों को खोजें जिनमें डबल शब्द (स्ट्रिंग या नंबर) शामिल हैं

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

आप यहां पूरा कोड देख सकते हैं:Https: // passatin.com / pk42 wg

इंस्टॉलपायथन। नीचे कोड क्या करता है?

प्रत्येक HTML फ़ाइल में मेरे पास एक PHP अनुक्रम है जिसमें इस चर है$ item_id = संख्या;

संख्या1 से 1600 (या आप जिस संख्या को आप चाहते हैं) की सीमा के बराबर है, उदाहरण के लिए एक फ़ाइल में हो सकता है$ ITEM_ID =HTML HILITE.ME का उपयोग करके उत्पन्नतेईस;और अन्य फ़ाइल में मेरे पास हो सकता है$ item_id = 1340;और इसी तरह..

मैं उन फ़ाइलों को ढूंढना चाहता हूं जिनमें दोहराए गए स्ट्रिंग में संख्याएं होती हैं। उदाहरण के लिए मेरे पास हो सकता है$ ITEM_ID =HTML HILITE.ME का उपयोग करके उत्पन्नतेईस;n एक फ़ाइल और समान हो सकता है$ ITEM_ID =HTML HILITE.ME का उपयोग करके उत्पन्नतेईस;अन्य फ़ाइल में। पायथन कोड में सहेजेगापरिणाम_ duplicates.txtसभी फ़ाइल नाम जिनमें इस प्रकार के डुप्लिकेट होते हैं।

कोडुल: किसी भी दुभाषिया कार्यक्रम में नीचे दिए गए कोड को कॉपी और चलाएं (मैं उपयोग करता हूं Pyscrcs

कोड:

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".

इसके अलावा, एक हैसंस्करण 2इस कोड यासंस्करण 3यासंस्करण 4यासंस्करण 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