跳转到主要内容

一个解析MT940文件并返回用于统计和操作的智能Python集合库。

项目描述

MT940 test status MT940 Pypi version MT940 code coverage https://img.shields.io/pypi/pyversions/mt-940.svg

mt940 - 一个解析MT940文件并返回用于统计和操作的智能Python集合库。

安装

要安装最新版本

pip install mt-940

如果没有安装pip

easy_install mt-940

要安装最新开发版本

git clone --branch develop https://github.com/WoLpH/mt940.git mt940
cd ./mt940
virtualenv .env
source .env/bin/activate
pip install -e .

要运行测试,可以使用py.test命令或直接运行tox以测试所有支持的Python版本中的所有内容。

用法

基本解析

import mt940
import pprint

transactions = mt940.parse('mt940_tests/jejik/abnamro.sta')

print('Transactions:')
print(transactions)
pprint.pprint(transactions.data)

print()
for transaction in transactions:
    print('Transaction: ', transaction)
    pprint.pprint(transaction.data)

为每笔交易设置开/关余额信息

import mt940
import pprint

mt940.tags.BalanceBase.scope = mt940.models.Transaction

# The currency has to be set manually when setting the BalanceBase scope to Transaction.
transactions = mt940.models.Transactions(processors=dict(
    pre_statement=[
        mt940.processors.add_currency_pre_processor('EUR'),
    ],
))

with open('mt940_tests/jejik/abnamro.sta') as f:
    data = f.read()

transactions.parse(data)

for transaction in transactions:
    print('Transaction: ', transaction)
    pprint.pprint(transaction.data)

简单的JSON编码

import json
import mt940


transactions = mt940.parse('mt940_tests/jejik/abnamro.sta')

print(json.dumps(transactions, indent=4, cls=mt940.JSONEncoder))

解析荷兰银行ASN的语句,其中标签61不符合Swift规范

def ASNB_mt940_data():
    with open('mt940_tests/ASNB/0708271685_09022020_164516.940.txt') as fh:
        return fh.read()

def test_ASNB_tags(ASNB_mt940_data):
    tag_parser = mt940.tags.StatementASNB()
    trs = mt940.models.Transactions(tags={
        tag_parser.id: tag_parser
    })

trs.parse(ASNB_mt940_data)
trs_data = pprint.pformat(trs.data, sort_dicts=False)
print(trs_data)

贡献

非常感谢您的帮助,但请记住在创建pull请求之前克隆开发分支并运行tox

Travis测试为flake8支持和测试覆盖率,因此在创建pull请求之前始终检查这些内容是好的。

开发分支: https://github.com/WoLpH/mt940/tree/develop

要运行测试

pip install -r mt940_tests/requirements.txt
py.test

或在所有可用的Python版本上运行测试

pip install tox
tox

信息

Python支持

Python 2.7, >= 3.3

博客

http://wol.ph/

源代码

https://github.com/WoLpH/mt940

文档

http://mt940.rtfd.org

变更日志

http://mt940.readthedocs.org/en/latest/history.html

API

http://mt940.readthedocs.org/zh/latest/modules.html

问题/路线图

https://github.com/WoLpH/mt940/issues

Travis

http://travis-ci.org/WoLpH/mt940

测试覆盖率

https://coveralls.io/r/WoLpH/mt940

Pypi

https://pypi.python.org/pypi/mt-940

Ohloh

https://www.ohloh.net/p/mt-940

许可

BSD.

git 仓库

$ git clone https://github.com/WoLpH/mt940.git

安装开发版

$ git clone https://github.com/WoLpH/mt940.git mt940
$ cd ./mt940
$ virtualenv .env
$ source .env/bin/activate
$ pip install -e .

测试

$ py.test

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

mt-940-4.30.0.tar.gz (21.8 kB 查看散列)

上传时间

构建分布

mt_940-4.30.0-py2.py3-none-any.whl (20.4 kB 查看散列)

上传时间 Python 2 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面