marton levente преди 9 месеца
родител
ревизия
c2edc85395
променени са 2 файла, в които са добавени 6 реда и са изтрити 3 реда
  1. 3 1
      anafapi/anafspv.py
  2. 3 2
      tests/test_anafspv.py

+ 3 - 1
anafapi/anafspv.py

@@ -89,7 +89,9 @@ class anafSPV(object):
     def download_message(self, cui, id_, details):
         response = self.session.get(self.BASEURL.format(self.DLURL.format(id_)), cookies=self.requests_cookies)
         os.makedirs(os.path.join(self.DLLOC, cui), exist_ok=True)
-        with open(os.path.join(self.DLLOC, cui, details + '.pdf'), 'wb') as file:
+        words = details.split()
+        result_string = ' '.join(words[:3]) if len(words) >= 3 else ' '.join(words[:2]) if len(words) == 2 else details
+        with open(os.path.join(self.DLLOC, cui, result_string + '.pdf'), 'wb') as file:
             file.write(response.content)
 
     def get_vector(self, cui):

+ 3 - 2
tests/test_anafspv.py

@@ -13,8 +13,9 @@ class spvTest(unittest.TestCase):
         requests_cookies = self.spv.get_cookies_from_browser()
         messages = self.spv.get_messages(10)
         pprint.pprint(messages)
-        # for message in messages['mesaje'][-1:]:  # -1:
-        #     self.spv.download_message(message['cif'], id_=message['id'], details=message['tip'])
+        for message in messages['mesaje'][-1:]:  # -1:
+            self.spv.download_message(message['cif'], id_=message['id'], details=message['detalii'])
+        # self.spv.download_message('27100508', id_='556755658', details=message['tip'])
 
     def test_get_fin_sheet(self):
         requests_cookies = self.spv.get_cookies_from_browser()