从plaid下载金融交易作为qif文件。
plaid2qif的Python项目详细描述
说明
提供从各种金融机构下载交易的机制(由Plaid支持),并转换为金融软件(特别是gnucash)可用的格式(特别是qif&csv,但可扩展)。
小结
# Save a long-lived access token (one-time only)
plaid2qif save-access-token --institution=<name> --public-token=<token> --credentials=<file> [--verbose]
# List out accunts that have been linked to Plaid
plaid2qif list-accounts --institution=<name> --credentials=<file> [--verbose]
# Download transactions in various formats (default QIF) from Plaid
plaid2qif download \
--institution=<name> \
--account=<account-name> \
--account-type=<type> \
--account-id=<acct-id> \
--from=<from-date> \
--to=<to-date> \
--credentials=<file> \
[--output-format=<format>] \
[--output-dir=<path>] \
[--ignore-pending] \
[--suppress-warnings=<tf>] \
[--verbose]
使用量
- 使用
pip
安装
plaid2qif
命令
$ pip install plaid2qif
验证并与您的金融机构链接(仅限第一次)--请参阅下面的“验证先决条件”。
配置好后,就可以下载事务并将其保存为qif文件:
plaid2qif download \
--from=<yyyy-mm-dd> \
--to=<yyyy-mm-dd> \
--institution=<name> \
--account-type=<type> \
--account=<account-name> \
--account-id=<plaid-account-id> \
--credentials=<file>
account
是指向gnucash分类帐中最终要将交易导入的帐户的路径。这将添加到qif文件中的!Account
头中。例如:Assets: Checking Accounts:Personal Checking Account
。如果名称有空格,请务必引用此参数。account-type
是帐户标识符类型,documented here。account-id
是要下载的帐户的plaid帐户id,通过上面的list-accounts
获得。- 默认情况下,输出将转到要重定向的stdout。如果要将其写入某个位置,请使用
output-dir
参数。
认证先决条件
- 获取您自己的格子花纹个人凭证并将其保存到本地文件中,例如
./plaid-credentials.json
。此json文件应包含以下键的值:
{
"client_id" : "<censored>",
"public_key" : "<censored>",
"secret" : "<censored>"
}
- 为要存储的机构配置数据创建一个
./cfg
目录。 - 向您的金融机构认证。
向您的金融机构进行身份验证的步骤
- 本地保存此HTML,例如
auth.html
<html>
<body>
<button id='linkButton'>Open Link - Institution Select</button>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script>
var linkHandler = Plaid.create({
env: 'development',
clientName: 'Plaid2QIF',
key: '[PUBLIC_KEY]', // Replace with your public_key from plaid-credentials.json
product: 'auth',
apiVersion: 'v2',
onLoad: function() {
// The Link module finished loading.
},
onSuccess: function(public_token, metadata) {
// Send the public_token to your app server here.
// The metadata object contains info about the institution the
// user selected and the account ID, if selectAccount is enabled.
console.log('public_token: '+public_token+', metadata: '+JSON.stringify(metadata));
},
onExit: function(err, metadata) {
// The user exited the Link flow.
if (err != null) {
// The user encountered a Plaid API error prior to exiting.
}
// metadata contains information about the institution
// that the user selected and the most recent API request IDs.
// Storing this information can be helpful for support.
}
});
// Trigger the standard institution select view
document.getElementById('linkButton').onclick = function() {
linkHandler.open();
};
</script>
</body>
</html>
- 打开根目录上的Web服务器并打开
auth.html
$ python3 -m http.server
$ open auth.html # edit first to add the public token from plaid-credentials.json
跟随instructions here使用ui将您的金融机构链接到plaid。
成功链接后,请查看浏览器控制台(例如在chrome上使用
⌘-⌥-i
),然后复制public_token
。public_token
是一个短期凭证。使用
public_token
,生成并保存长寿命access_token
凭据:
$ plaid2qif save-access-token --institution=<name> --public-token=<token> --credentials=<plaid-credentials-file>
institution
应该是可以用作有效(即:[a-zA-Z0-9_]
)文件名的字符串,用于存储access_token
。
- 列出与该机构相关的账户,以便获得格纹
account_id
:
$ plaid2qif list-accounts --institution=<name> --credentials=<plaid-credentials-file>
分布
# increment version in `plaid2qif/__init__.py`
# commit everything & push
$ git tag -s vX.Y.Z
$ git push --tags
$ python3 setup.py sdist bdist_wheel
$ twine upload dist/*