Bladeren bron

another variant to handle zip files

if no xml files then extract all, else walk thorough xmls and check if
id_ in file
marton levente 3 maanden geleden
bovenliggende
commit
480cfed905
1 gewijzigde bestanden met toevoegingen van 19 en 8 verwijderingen
  1. 19 8
      anafapi/anafoauth.py

+ 19 - 8
anafapi/anafoauth.py

@@ -362,14 +362,25 @@ class Efactoauth(Anafoauth):
             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'))
-            if os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml') not in xml_files \
-                    and os.path.join(dest_f, name[0]).count('_') < 2:
-                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)
-                # print(self.xml_inv)
-                # if os.path.exists(self.xml_inv.replace('.xml', '') + '_booked.xml'):
-                #     os.remove(self.xml_inv)
-                    return self.xml_inv
+            if len(xml_files) < 1:
+                if os.path.join(dest_f, name[0].replace('.xml', '') + '_booked.xml') not in xml_files:
+                        # and os.path.join(dest_f, name[0]).count('_') < 2:
+                    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)
+                        # print(self.xml_inv)
+                        # if os.path.exists(self.xml_inv.replace('.xml', '') + '_booked.xml'):
+                        #     os.remove(self.xml_inv)
+                        return self.xml_inv
+            else:
+                for file in xml_files:
+                    if name[0].replace('.xml', '') not in file and file.count('_') < 2:
+                        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)
+                            # print(self.xml_inv)
+                            # if os.path.exists(self.xml_inv.replace('.xml', '') + '_booked.xml'):
+                            #     os.remove(self.xml_inv)
+                            return self.xml_inv
+
         else:
             inv_zip = ZipFile(io.BytesIO(self.zip_inv), mode='r')
             name = [name for name in inv_zip.namelist() if 'semnatura' not in name]