Ejemplo n.º 1
0
Archivo: gui.py Proyecto: Pavit/pyofx
    def on_download_clicked(self):
        """ Read GUI widgets """
        # Client instance attributes
        client_opts = {key: self.read_widget(getattr(self, key))
                        for key in OFXClient.defaults.keys()}
        client = OFXClient(**client_opts)

        # Statement options
        stmt_options = {}
        for option in OFXClient.stmt_defaults.keys():
            widget = getattr(self, option, None)
            stmt_options[option] = self.read_widget(widget)

        # Account numbers
        accts = {key: self.read_widget(getattr(self, key))
                        for key in OFXClient.acct_defaults.keys()}
        acct_tuple = client.parse_account_strings(**accts)

        client.request_all(*acct_tuple, **stmt_options)
        user = self.read_widget(self.user)

        if self.dry_run.isChecked():
            request = client.write_request(user, 'TOPSECRET')
            msg = QtGui.QMessageBox(self, windowTitle='OFX Request',
                text='OFX request prepared for %s' % self.fi_name)
            msg.setDetailedText(request)
            msg.exec_()
            return

        password = self.get_password(user)

        if self.profile.isChecked():
            client.request_profile(user=user, password=password)
            archive_file = 'profile.ofx'
        else:
            client.write_request(user=user, password=password)
            # FIXME - ought to use DTCLIENT from the SONRQ here
            import datetime
            archive_file = '%s.ofx' % datetime.datetime.now().strftime('%Y%m%d%H%M%S')
        response = client.download(user, password)
        clicked = self.popup_response(response.read())
        if clicked == QtGui.QMessageBox.Save:
            archive_dir = _(os.path.join(self.config.get('global', 'dir'), self.fi_name))
            if archive_dir == '':
                return
            if not os.path.exists(archive_dir):
                os.makedirs(archive_dir)
            archive_path = os.path.join(archive_dir, archive_file)
            archive_path = QtGui.QFileDialog.getSaveFileName(self,
                            directory=archive_path,
                            filter='OFX files (*.ofx);;All files (*)')
            with open(archive_path, 'w') as archive:
                archive.write(response.read())
Ejemplo n.º 2
0
        with open("sites.json", "r") as f:
            sites = json.load(f)
    except IOError as e:
        print 'no "sites.json" file detected'

    dtstart = time.strftime("%Y%m%d%H%M%S", findLastTime(argv[1]))
    dtnow = time.strftime("%Y%m%d%H%M%S", time.localtime())

    if len(argv) < 4:
        print "Usage:", argv[
            0
        ], "site user password [account1,[account2,[account3...]]] [CHECKING/SAVINGS/.. if downloading from bank account]"
        print "available sites:", join(", ", sites.keys())
        sys.exit()
    passwd = argv[3]
    client = OFXClient(sites[argv[1]], argv[2], passwd)

    if len(argv) < 5:
        query = client.acctQuery("19700101000000")
        client.doQuery(query, argv[1] + "_acct.ofx")
    else:
        if "CCSTMT" in sites[argv[1]]["caps"]:
            query = client.ccQuery(argv[4].split(","), dtstart)
        elif "INVSTMT" in sites[argv[1]]["caps"]:
            query = client.invstQuery(sites[argv[1]]["fiorg"], argv[4].split(","), dtstart, dtnow)
        elif "BASTMT" in sites[argv[1]]["caps"]:
            query = client.baQuery(sites[argv[1]]["bankid"], argv[4].split(","), dtstart, dtnow, argv[5])
        client.doQuery(query, argv[1] + dtnow + ".ofx")

    os.startfile('"' + os.getcwd() + "\\" + outfile + '"')
Ejemplo n.º 3
0
    try:
        with open("sites.json", "r") as f:
            sites = json.load(f)
    except IOError as e:
        print 'no "sites.json" file detected'

    dtstart = time.strftime("%Y%m%d%H%M%S", findLastTime(argv[1]))
    dtnow = time.strftime("%Y%m%d%H%M%S", time.localtime())

    if len(argv) < 4:
        print "Usage:", argv[
            0], "site user password [account1,[account2,[account3...]]] [CHECKING/SAVINGS/.. if downloading from bank account]"
        print "available sites:", join(", ", sites.keys())
        sys.exit()
    passwd = argv[3]
    client = OFXClient(sites[argv[1]], argv[2], passwd)

    if len(argv) < 5:
        query = client.acctQuery("19700101000000")
        client.doQuery(query, argv[1] + "_acct.ofx")
    else:
        if "CCSTMT" in sites[argv[1]]["caps"]:
            query = client.ccQuery(argv[4].split(","), dtstart)
        elif "INVSTMT" in sites[argv[1]]["caps"]:
            query = client.invstQuery(sites[argv[1]]["fiorg"],
                                      argv[4].split(","), dtstart, dtnow)
        elif "BASTMT" in sites[argv[1]]["caps"]:
            query = client.baQuery(sites[argv[1]]["bankid"],
                                   argv[4].split(","), dtstart, dtnow, argv[5])
        client.doQuery(query, argv[1] + dtnow + ".ofx")