Ejemplo n.º 1
0
    def to_xml(self):
        ofx102 = self.to_ofx102()

        if self.debug:
            sys.stderr.write(ofx102 + "\n")
            sys.stderr.write("Parsing OFX/1.02.\n")
        response = ofx.Response(ofx102, debug=self.debug)

        if self.debug: sys.stderr.write("Making OFX/2.0.\n")

        xml = response.as_xml(original_format="OFC")

        return xml
Ejemplo n.º 2
0
    def to_xml(self):
        ofx102 = self.to_ofx102()

        if self.debug:
            sys.stderr.write(ofx102 + "\n")
            sys.stderr.write("Parsing OFX/1.02.\n")
        response = ofx.Response(ofx102) #, debug=self.debug)

        if self.debug: sys.stderr.write("Making OFX/2.0.\n")
        if self.dayfirst:
            date_format = "DD/MM/YY"
        else:
            date_format = "MM/DD/YY"
        xml = response.as_xml(original_format="QIF", date_format=date_format)

        return xml
Ejemplo n.º 3
0
    def _send_request(self, url, request_body):
        """Transmits the message to the server and checks the response
        for error status."""

        request = urllib2.Request(
            url, request_body, {
                "Content-type": "application/x-ofx",
                "Accept": "*/*, application/x-ofx"
            })
        stream = urllib2.urlopen(request)
        response = stream.read()
        stream.close()

        if self.debug:
            print response

        response = ofx.Response(response)
        response.check_signon_status()

        parsed_ofx = response.as_dict()

        # FIXME: This needs to account for statement closing responses.

        if parsed_ofx.has_key("BANKMSGSRSV1"):
            bank_status = \
                parsed_ofx["BANKMSGSRSV1"]["STMTTRNRS"]["STATUS"]
            self._check_status(bank_status, "bank statement")

        elif parsed_ofx.has_key("CREDITCARDMSGSRSV1"):
            creditcard_status = \
                parsed_ofx["CREDITCARDMSGSRSV1"]["CCSTMTTRNRS"]["STATUS"]
            self._check_status(creditcard_status, "credit card statement")

        elif parsed_ofx.has_key("SIGNUPMSGSRSV1"):
            acctinfo_status = \
                parsed_ofx["SIGNUPMSGSRSV1"]["ACCTINFOTRNRS"]["STATUS"]
            self._check_status(acctinfo_status, "account information")

        return response
Ejemplo n.º 4
0
 def setUp(self):
     self.response_text = ofx_test_utils.get_checking_stmt()
     self.response = ofx.Response(self.response_text)
Ejemplo n.º 5
0
def convert(text,
            filetype,
            verbose=False,
            fid="UNKNOWN",
            org="UNKNOWN",
            bankid="UNKNOWN",
            accttype="UNKNOWN",
            acctid="UNKNOWN",
            balance="UNKNOWN",
            curdef=None,
            lang="ENG",
            dayfirst=False,
            debug=False):

    # This finishes a verbosity message started by the caller, where the
    # caller explains the source command-line option and this explains the
    # source format.
    if verbose:
        sys.stderr.write("Converting from %s format.\n" % filetype)

    if options.debug and (filetype in ["OFC", "QIF"]
                          or filetype.startswith("OFX")):
        sys.stderr.write("Starting work on raw text:\n")
        sys.stderr.write(rawtext + "\n\n")

    if filetype.startswith("OFX/2"):
        if verbose:
            sys.stderr.write("No conversion needed; returning unmodified.\n")

        # The file is already OFX 2 -- return it unaltered, ignoring
        # any of the parameters passed to this method.
        return text

    elif filetype.startswith("OFX"):
        if verbose: sys.stderr.write("Converting to OFX/2.0...\n")

        # This will throw a ParseException if it is unable to recognize
        # the source format.
        response = ofx.Response(text, debug=debug)
        return response.as_xml(original_format=filetype)

    elif filetype == "OFC":
        if verbose: sys.stderr.write("Beginning OFC conversion...\n")
        converter = ofxtools.OfcConverter(text,
                                          fid=fid,
                                          org=org,
                                          curdef=curdef,
                                          lang=lang,
                                          debug=debug)

        # This will throw a ParseException if it is unable to recognize
        # the source format.
        if verbose:
            sys.stderr.write("Converting to OFX/1.02...\n\n%s\n\n" %
                             converter.to_ofx102())
            sys.stderr.write("Converting to OFX/2.0...\n")

        return converter.to_xml()

    elif filetype == "QIF":
        if verbose: sys.stderr.write("Beginning QIF conversion...\n")
        converter = ofxtools.QifConverter(text,
                                          fid=fid,
                                          org=org,
                                          bankid=bankid,
                                          accttype=accttype,
                                          acctid=acctid,
                                          balance=balance,
                                          curdef=curdef,
                                          lang=lang,
                                          dayfirst=dayfirst,
                                          debug=debug)

        # This will throw a ParseException if it is unable to recognize
        # the source format.
        if verbose:
            sys.stderr.write("Converting to OFX/1.02...\n\n%s\n\n" %
                             converter.to_ofx102())
            sys.stderr.write("Converting to OFX/2.0...\n")

        return converter.to_xml()

    else:
        raise TypeError("Unable to convert source format '%s'." % filetype)
Ejemplo n.º 6
0
 def test_statement_as_xml(self):
     response = ofx.Response(self.checking)
     self.assertEqual('<?xml version="1.0"', response.as_xml()[:19])