lib-ftep 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.3
2
+ Name: lib-ftep
3
+ Version: 0.1.0
4
+ Summary:
5
+ Author: Nathan Blum
6
+ Author-email: n.blum@student.tudelft.nl
7
+ Requires-Python: >=3.10
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: lib-idoc (>=0.1.1,<0.2.0)
14
+ Requires-Dist: lib-invoice (>=0.1.1,<0.2.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # lib-ftep
@@ -0,0 +1 @@
1
+ # lib-ftep
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "lib-ftep"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ {name = "Nathan Blum",email = "n.blum@student.tudelft.nl"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "lib-idoc (>=0.1.1,<0.2.0)",
12
+ "lib-invoice (>=0.1.1,<0.2.0)"
13
+ ]
14
+
15
+ [tool.poetry]
16
+ packages = [{include = "lib_ftep", from = "src"}]
17
+
18
+
19
+ [build-system]
20
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
21
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,5 @@
1
+ from .ftp import FTP_
2
+
3
+ __all__ = [
4
+ 'FTP_',
5
+ ]
@@ -0,0 +1,36 @@
1
+ import os
2
+ import logging
3
+ from ftplib import FTP
4
+ from io import BytesIO
5
+ from lib_invoice import Invoice
6
+ from lib_idoc import IDOC
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ class FTP_:
11
+ def __init__(self):
12
+ self.ftp_hostname = os.getenv('FTP_HOSTNAME')
13
+ self.ftp_username = os.getenv('FTP_USERNAME')
14
+ self.ftp_password = os.getenv('FTP_PASSWORD')
15
+ self.ftp_location_idoc = os.getenv('FTP_LOCATION_IDOC')
16
+ self.ftp_location_pdf = os.getenv('FTP_LOCATION_PDF')
17
+ self.ftp = None
18
+
19
+ def connect(self):
20
+ """Connects to the FTP server."""
21
+ self.ftp = FTP(self.ftp_hostname)
22
+ self.ftp.login(self.ftp_username, self.ftp_password)
23
+
24
+ def upload_idoc(self, idoc: IDOC):
25
+ """Uploads a file to the FTP server."""
26
+ self.ftp.cwd(self.ftp_location_idoc)
27
+ stream = BytesIO(idoc.xml.encode('utf-8'))
28
+ self.ftp.storbinary(f"STOR {idoc.xml_filename}", stream)
29
+ logger.info(f"Uploaded idoc: {idoc.xml_filename}")
30
+
31
+ def upload_pdf(self, invoice: Invoice):
32
+ """Uploads a file to the FTP server."""
33
+ self.ftp.cwd(self.ftp_location_pdf)
34
+ stream = BytesIO(invoice.pdf)
35
+ self.ftp.storbinary(f"STOR {invoice.pdf_filename}", stream)
36
+ logger.info(f"Uploaded pdf: {invoice.pdf_filename}")