thắc mắc Nhờ aE biết macro EmEditor hoặc script Python hỗ trợ

  • Người tạo chủ đề Người tạo chủ đề GR666N
  • Ngày bắt đầu Ngày bắt đầu

GR666N

Senior Member
Tình hình là e nhờ thằng ChatGPT viết hộ mấy cái macro EmEditor mà toàn bị lỗi không chạy được, đành lên đây nhờ các bác biết code macro Emeditor/Python giúp ợ

Dữ liệu của e có dạng thế này: https://files.catbox.moe/o550dm.txt


Macro 1: Xóa toàn bộ địa chỉ email có từ khóa trong file blacklist txt
Mã:
blacklist.txt có nội dung thế này
sales
yahoo
hotmail
sale@
vozer@
...
Còn đây là macro do thằng ChatGPT code
JavaScript:
// Ask for the location of the blacklist file
var strBlacklistFile = document.GetFilename( eeDlgOpen, "", "Text Files (*.txt)|*.txt||", "Select the Blacklist file" );

if( strBlacklistFile == "" ){
    alert( "No file selected" );
    return;
}

// Read the blacklist file into an array
var arrBlacklist = new Array();
var objFS = new ActiveXObject( "Scripting.FileSystemObject" );
var objFile = objFS.OpenTextFile( strBlacklistFile, 1 );
while( !objFile.AtEndOfStream ){
    var strLine = objFile.ReadLine();
    if( strLine != "" ) arrBlacklist.push( strLine );
}
objFile.Close();

// Define the regular expression pattern to match email addresses
var reEmail = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i;

// Loop through each line of the document and remove any emails that match the blacklist
document.selection.StartOfDocument();
while( !document.selection.EndOfDocument ){
    if( document.selection.Find( reEmail ) ){
        var strEmail = document.selection.Text;
        for( var i = 0; i < arrBlacklist.length; i++ ){
            if( strEmail.indexOf( arrBlacklist[i] ) >= 0 ){
                document.selection.Delete();
                break;
            }
        }
    }else{
        break;
    }
}

// Alert when finished
alert( "Done" );

Macro 2: Dòng nào có nhiều email thì tách thành các dòng giống nhau nhưng chỉ chứa 1 email

Macro do thằng ChatGPT code
JavaScript:
// Define the regular expression pattern to match email addresses
var reEmail = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/ig;

// Loop through each line of the document and split any lines that contain multiple emails
document.selection.StartOfDocument();
while( !document.selection.EndOfDocument ){
    var strLine = document.selection.Text;
    if( reEmail.test( strLine ) ){
        var arrMatches = strLine.match( reEmail );
        for( var i = 0; i < arrMatches.length; i++ ){
            document.selection.Text = arrMatches[i] + "\n";
            document.selection.LineDown();
        }
    }
    document.selection.LineDown();
}

// Alert when finished
alert( "Done" );
Em xin cám ơn nhìu ợ :sweet_kiss:
 
Sửa lần cuối:
khổ cái file dữ liệu lớn quá (gần 100MB), xóa bằng regex notepad++ bị treo mất tiêu =((

Python do ChatGPT viết
JavaScript:
import os

# Nhập đường dẫn của file dữ liệu và danh sách đen
data_file_path = input("Nhập đường dẫn của file dữ liệu: ")
blacklist_file_path = input("Nhập đường dẫn của file danh sách đen: ")

# Đọc danh sách đen
with open(blacklist_file_path, "r", encoding="utf-8") as blacklist_file:
    blacklist = blacklist_file.read().splitlines()

# Xóa toàn bộ email trong các dòng của file dữ liệu chứa từ khóa trong danh sách đen
with open(data_file_path, "r", encoding="utf-8") as data_file:
    lines = data_file.readlines()
    new_lines = []
    for line in lines:
        if not any(keyword in line for keyword in blacklist):
            # Nếu không có từ khóa trong dòng, giữ nguyên dòng đó
            new_lines.append(line)

# Lưu kết quả vào file kết quả
with open("ketqua.txt", "w", encoding="utf-8") as result_file:
    result_file.writelines(new_lines)

print("Hoàn thành!")
 
Sửa lần cuối:

Thống kê chủ đề

Ngày tạo
GR666N,
Người trả lời cuối
Decepticon,
Trả lời
5
Lượt xem
702
Quay lại
Lên đầu trang