Browse Source

resolved multiple zipfiles extract (xml_files) + rem. notifs

marton levente 4 months ago
parent
commit
1512105eeb
1 changed files with 7 additions and 5 deletions
  1. 7 5
      anafapi/anafoauth.py

+ 7 - 5
anafapi/anafoauth.py

@@ -49,7 +49,7 @@ class Anafoauth(object):
         print(expires_at.strftime('%d-%m-%Y %H:%M:%S'))
         print(expires_at.strftime('%d-%m-%Y %H:%M:%S'))
         return expires_at > datetime.datetime.today()
         return expires_at > datetime.datetime.today()
 
 
-    def jwt_props(self, path):
+    def jwt_props(self, path) -> dict:
         with open(path) as token_file:
         with open(path) as token_file:
             token_dict = ujson.load(token_file)
             token_dict = ujson.load(token_file)
         token = token_dict['access_token']
         token = token_dict['access_token']
@@ -298,8 +298,8 @@ class Efactoauth(Anafoauth):
                 # print(dirs)
                 # print(dirs)
                 os.makedirs(dirs, exist_ok=True)
                 os.makedirs(dirs, exist_ok=True)
                 new = self.download_invoice(download_id=inv['id'], path=dirs, env=env)
                 new = self.download_invoice(download_id=inv['id'], path=dirs, env=env)
-                if new:
-                    self.notify_new(date=date_, cif=cif, type_=type_)
+                # if new:
+                #     self.notify_new(date=date_, cif=cif, type_=type_)
                 files = os.path.join(dirs, f'{inv["id"]}.zip')
                 files = os.path.join(dirs, f'{inv["id"]}.zip')
                 if extract:
                 if extract:
                     self.getxml_from_zip(path=files, dest_f=dirs)
                     self.getxml_from_zip(path=files, dest_f=dirs)
@@ -360,8 +360,9 @@ class Efactoauth(Anafoauth):
             name = [name for name in inv_zip.namelist() if 'semnatura' not in name]
             name = [name for name in inv_zip.namelist() if 'semnatura' not in name]
             files_in_folder = os.listdir(dest_f)
             files_in_folder = os.listdir(dest_f)
             xml_files = [file for file in files_in_folder if file.lower().endswith('.xml')]
             xml_files = [file for file in files_in_folder if file.lower().endswith('.xml')]
+            # print(xml_files)
             # print(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml'))
             # print(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml'))
-            if not xml_files:
+            if os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml') not in xml_files:
                 if not os.path.exists(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml')):
                 if not os.path.exists(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml')):
                     self.xml_inv = self._extract_zipfile(inv_zip, dest_f=dest_f)
                     self.xml_inv = self._extract_zipfile(inv_zip, dest_f=dest_f)
                 # print(self.xml_inv)
                 # print(self.xml_inv)
@@ -373,7 +374,8 @@ class Efactoauth(Anafoauth):
             name = [name for name in inv_zip.namelist() if 'semnatura' not in name]
             name = [name for name in inv_zip.namelist() if 'semnatura' not in name]
             files_in_folder = os.listdir(dest_f)
             files_in_folder = os.listdir(dest_f)
             xml_files = [file for file in files_in_folder if file.lower().endswith('.xml')]
             xml_files = [file for file in files_in_folder if file.lower().endswith('.xml')]
-            if not xml_files:
+            # if not xml_files:
+            if os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml') not in xml_files:
                 if not os.path.exists(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml')):
                 if not os.path.exists(os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml')):
                     self.xml_inv = self._extract_zipfile(inv_zip, dest_f=dest_f)
                     self.xml_inv = self._extract_zipfile(inv_zip, dest_f=dest_f)
                 # print(self.xml_inv.replace('.xml', '') + '_booked.xml')
                 # print(self.xml_inv.replace('.xml', '') + '_booked.xml')