import re

filename1 = "test.txt"
filename2 = "words0.csv"
filename3 = "words2.csv"

words1one = {}# hash
with open(filename2, 'r') as f:
    file_data = f.readlines()
    for line in file_data:
        if (re.match(r'^#',line)):
            continue
        else:
            pairs = line.split(";")
            words1one[pairs[0]] = pairs[1]

words2one = {}# hash
with open(filename3, 'r') as f:
    file_data = f.readlines()
    for line in file_data:
        if (re.match(r'^#',line)):
            continue
        else:
            pairs = line.split(";")
            words2one[pairs[0]] = pairs[1]

def gyaru_conv(string,dictionary): # strings,hash
    string = string.rstrip("\n")
    temptext = ""
    for word1,word2 in dictionary.items():
        #    print(word1,word2)
        temptext = re.sub(rf"{word1}",word2,string)
        #text = string.replace(word1,word2)
        temptext = re.sub(r'\n','',temptext)
        temptext = re.sub(r'\\','',temptext)
        string = temptext
    return string

text = ""
with open(filename1,'r') as f:
    line = f.readline()
    while (line != ''):
        text += gyaru_conv(line,words1one) # strings,hash
        text = gyaru_conv(text,words2one) # strings,hash
        line = f.readline()

print(text)
Edit
Pub: 03 Oct 2022 17:27 UTC
Edit: 03 Oct 2022 17:27 UTC
Views: 154