Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Last active December 31, 2020 06:40
Show Gist options
  • Save drygdryg/6125a54e5a846472e7e0960b377c1200 to your computer and use it in GitHub Desktop.
Save drygdryg/6125a54e5a846472e7e0960b377c1200 to your computer and use it in GitHub Desktop.
Merging Router Scan CSV report files
import sys
import os
import csv
try:
core_file = sys.argv[1]
except IndexError:
print('Использование: {} файлназначения.csv'.format(sys.argv[0]))
exit(1)
wr = csv.writer(open(core_file, 'a'), delimiter=';', quoting=csv.QUOTE_ALL)
files = list(filter(lambda x: x.endswith('.csv'), os.listdir()))
if len(files):
print('Найдено файлов: {}'.format(len(files)))
else
print('Ошибка: файлы не найдены')
exit(1)
success = 0
for file in files:
fl = open(file, 'r')
reader = csv.reader(fl, delimiter=';')
n = 1
c = 0
next(reader)
for line in reader:
try:
if (line[8] or line[9]) != '':
wr.writerow(line)
success += 1
else:
print('В файле {} не обработана запись {}: пустое содержимое'.format(file, n))
except IndexError:
print('IndexError was excepted. File: {}'.format(file))
print('Успешно обработано записей:', success)
if input('Удалить обработанные файлы? (y/n) : ') == 'y':
for file in files:
os.remove(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment