Ejemplo n.º 1
0
    def serialize(self,
                  ofx,
                  version=None,
                  prettyprint=False,
                  close_elements=True):
        if version is None:
            version = self.version
        header = make_header(version=version, newfileuid=self.uuid)
        header = bytes(str(header), "utf_8")

        tree = ofx.to_etree()
        if prettyprint:
            utils.indent(tree)

        # Some servers choke on OFXv1 requests including ending tags for
        # elements (which are optional per the spec).
        if close_elements is False:
            if version >= 200:
                msg = "OFX version {} requires ending tags for elements"
                raise ValueError(msg.format(version))
            body = utils.tostring_unclosed_elements(tree)
        else:
            # ``method="html"`` skips the initial XML declaration
            body = ET.tostring(tree, encoding="utf_8", method="html")

        return header + body
Ejemplo n.º 2
0
    def serialize(self,
                  ofx: OFX,
                  version: Optional[int] = None,
                  prettyprint: Optional[bool] = None,
                  close_elements: Optional[bool] = None,
                  ) -> bytes:
        if version is None:
            version = self.version
        if prettyprint is None:
            prettyprint = self.prettyprint
        if close_elements is None:
            close_elements = self.close_elements
        header = bytes(str(make_header(version=version, newfileuid=self.uuid)),
                       "utf_8")

        tree = ofx.to_etree()
        if prettyprint:
            utils.indent(tree)

        # Some servers choke on OFXv1 requests including ending tags for
        # elements (which are optional per the spec).
        if close_elements is False:
            if version >= 200:
                msg = "OFX version {} requires ending tags for elements"
                raise ValueError(msg.format(version))
            body = utils.tostring_unclosed_elements(tree)
        else:
            # ``method="html"`` skips the initial XML declaration
            body = ET.tostring(tree, encoding="utf_8", method="html")

        return header + body
Ejemplo n.º 3
0
    def serialize(
        self,
        ofx: OFX,
        version: Optional[int] = None,
        oldfileuid: Optional[str] = None,
        newfileuid: Optional[str] = None,
        prettyprint: Optional[bool] = None,
        close_elements: Optional[bool] = None,
    ) -> bytes:
        """
        Transform a ``models.OFX`` instance into bytestring representation
        with OFX header prepended.

        N.B. ``version`` / ``prettyprint`` / ``close_elements`` kwargs are
        basically hacks for ``scripts.ofxget.scan_profile()``; ordinarily you
        should initialize the ``OFXClient`` with the proper version# and
        formatting parameters, rather than overriding the client config here.

        Optional kwargs:
            ``version`` - OFX version to report in header
            ``oldfileuid`` - OLDFILEUID to report in header
            ``newfileuid`` - NEWFILEUID to report in header
            ``prettyprint`` - add newlines between tags and indentation
            ``close_elements`` - add markup closing tags to leaf elements
        """
        if version is None:
            version = self.version
        if prettyprint is None:
            prettyprint = self.prettyprint
        if close_elements is None:
            close_elements = self.close_elements
        header = bytes(
            str(
                make_header(
                    version=version, oldfileuid=oldfileuid, newfileuid=newfileuid
                )
            ),
            "utf_8",
        )

        tree = ofx.to_etree()
        if prettyprint:
            utils.indent(tree)

        # Some servers choke on OFXv1 requests including ending tags for
        # elements (which are optional per the spec).
        if close_elements is False:
            if version >= 200:
                raise ValueError(
                    f"OFX version {version} requires ending tags for elements"
                )
            body = utils.tostring_unclosed_elements(tree)
        else:
            # ``method="html"`` skips the initial XML declaration
            body = ET.tostring(tree, encoding="utf_8", method="html")

        return header + body
Ejemplo n.º 4
0
def get_ofx_header():
    return str(make_header(version=220))
Ejemplo n.º 5
0
               invstmtmsgsrsv1=investmsgsrs,
               seclistmsgsrsv1=seclist)


filename = sys.argv[1]
p = subprocess.run([
    "java", "-jar", "pdfbox-app-2.0.19.jar", "ExtractText", "-console",
    filename
],
                   capture_output=True)
text = p.stdout.decode()

tl = text.split('\n')
account = breakdown_by_account(tl)
for a in account:
    if isinstance(a, CashActivity) or not a.account_no:
        continue
    sys.stderr.write(a.account_no)
    sys.stderr.write(" => ")
    sys.stderr.write(a.name)
    sys.stderr.write("\n")

ofx = get_ofx(account)

root = ofx.to_etree()
header = str(make_header(version=220))
message = ET.tostring(root).decode()

print(header)
print(message)
Ejemplo n.º 6
0
 def ofxheader(self):
     """ Prepend to OFX markup. """
     header = make_header(version=self.version, newfileuid=self.uuid)
     return bytes(str(header), "utf_8")