aboutsummaryrefslogtreecommitdiffstats
path: root/.github/scripts/analytics/decode_imported_csv.py
blob: 544aa1a86aa9c883bd633a4e52b368a9e8784607 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# NOT USED ANYWHERE, YOU CAN DELETE THIS IF YOU KNOW WHAT ARE YOU DOING
import os
import csv
import urllib.parse

# Функция для декодирования percent-encoded строки
def decode_percent_encoded_string(encoded_string):
    return urllib.parse.unquote(encoded_string)

# Функция для декодирования CSV файла
def decode_csv(file_path):
    with open(file_path, mode='r', encoding='utf-8') as infile, open(file_path + '.decoded', mode='w', encoding='utf-8', newline='') as outfile:
        reader = csv.reader(infile)
        writer = csv.writer(outfile,escapechar='\\', quotechar='"', quoting=csv.QUOTE_ALL, doublequote=True)

        for row in reader:
            decoded_row = [decode_percent_encoded_string(cell) for cell in row]
            writer.writerow(decoded_row)

# Функция для обработки всех CSV файлов в директории
def decode_all_csv_files_in_directory(directory_path):
    for filename in os.listdir(directory_path):
        if filename.endswith('.csv'):
            file_path = os.path.join(directory_path, filename)
            print(f"Processing file: {file_path}")
            decode_csv(file_path)
            os.replace(file_path + '.decoded', file_path)

def main(): 
    directory_path = 'place_your_path_here'
    decode_all_csv_files_in_directory(directory_path)
    
    
if __name__ == "__main__":
    main()