Alex Sidorov 1 year ago
parent
commit
946127f174
2 changed files with 15 additions and 13 deletions
  1. 2 3
      logger.py
  2. 13 10
      main.py

+ 2 - 3
logger.py

@@ -1,11 +1,10 @@
-import os
+import os, sys
 from datetime import datetime
 import logging
 
 def create_logger():
     now = datetime.now()
-    file_log = os.path.join(os.path.dirname(__file__), F'logs_{now.year}{now.month}{now.day}.log')
-    print(file_log)
+    file_log = os.path.join(os.path.dirname(sys.argv[0]), F'logs_{now.year}{now.month}{now.day}.log')
     logging.basicConfig(filename=file_log,
                         encoding='utf-8',
                         level=logging.DEBUG,

+ 13 - 10
main.py

@@ -1,25 +1,20 @@
-import csv
-import os
-import re
-import datetime
-import argparse
+import csv, os, re, sys, argparse
 from logger import *
 from datetime import datetime
 
 
-
+   
 parse = argparse.ArgumentParser(
     description="Программа для сбора информации из csv файлов")
 parse.add_argument('-p', '--path', help='Указать в какой директории искать',
-                   default=os.path.dirname(__file__))
+                   default=os.path.dirname(sys.argv[0]))
 parse.add_argument('-e', '--encoding',
-                   help='Указать в какой кодировке сохранять', default='utf-8')
+                   help='Указать в какой кодировке сохранять', default='windows-1251')
 parse.add_argument('-s', '--open_encoding',
                    help='Указать в какой кодировке открывать', default='utf-16')
 args = parse.parse_args()
 
 print(args)
-# DIR_WORK = "./sbor"
 LIST_BAD_ADAPTER = ['Wireless', 'Bluetooth', 'Wireless', 'WiFi',
                     'Kaspersky', 'VirtualBox', 'TAP-Windows',
                     'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
@@ -42,6 +37,7 @@ class ObjectReady:
             return ';'.join((self.frame, self.cabinet))
 
         dic = self.__dict__
+        # print(dic)
         try:
             row_interface = ';'.join(
                 [';'.join((dic.get(F"ip{i}"), dic.get(F"mac{i}"))) for i in range(self.count_interface)
@@ -113,7 +109,7 @@ def get_ready_information() -> list[ObjectReady]:
     for path in get_paths():
 
         obj = ObjectReady()
-        obj.frame = path.split('/')[-2]
+        obj.frame = os.path.basename(os.path.dirname(path))
         obj.cabinet = re.findall(
             r"\/([\w+?\ ?[а-яА-Я]+\ ?|\w+?\ ?[a-zA-Z]+\ ?|\d+])[\.|\,]", path)[-1]
 
@@ -138,9 +134,16 @@ def create_csv(list_obj: list[ObjectReady]) -> None:
         f.write(header_csv)
 
         for obj in list_obj:
+            row = obj.get_csv_row()
+            logger.info(row)
             f.write(obj.get_csv_row())
             
 
 if __name__ == '__main__':
     create_logger()
+    
+    logger.info("Start programm")
+    logger.info(F"Base dir: {args.path}")
+    
     create_csv(get_ready_information())
+    logger.info("Stop programm")