MICR = The line of digits printed using magnetic ink at the bottom of
a check.
Does anyone know of a Python function that has been written to parse a
line of MICR data?
Or, some financial package that may contain such a thing?
Or, in general, where I should be looking when looking for a piece of
Python code that may have already been written by someone?
I'm working on a project that involves a check scanner the produces
the raw MICR line as text.
Now, that raw MICR needs to be parsed for the various pieces of info.
The problem with MICR is that there is no standard layout. There are
some general rules for item placement, but beyond that it is up to the
individual banks to define how they choose to position the
information.
I did find an old C program written by someone at IBM... But I've read
it and it is Not code that would nicely convert to Python (maybe its
all the Python I'm used to, be it seems very poorly written).
Here is the link to that C code: ftp://ftp.software.ibm.com/software/...0/4610micr.zip
I've even tried using boost to generate a Python module, but that
didn't go well, and in the end is not going to be a solution for me
anyway.. really need access to the Python source.
Any help at all would be appreciated,
-mkp 4 4193
On Mar 24, 2:05 pm, "mkppk" <barnaclej...@g mail.comwrote:
MICR = The line of digits printed using magnetic ink at the bottom of
a check.
Does anyone know of a Python function that has been written to parse a
line of MICR data?
Or, some financial package that may contain such a thing?
Or, in general, where I should be looking when looking for a piece of
Python code that may have already been written by someone?
I'm working on a project that involves a check scanner the produces
the raw MICR line as text.
Now, that raw MICR needs to be parsed for the various pieces of info.
The problem with MICR is that there is no standard layout. There are
some general rules for item placement, but beyond that it is up to the
individual banks to define how they choose to position the
information.
I did find an old C program written by someone at IBM... But I've read
it and it is Not code that would nicely convert to Python (maybe its
all the Python I'm used to, be it seems very poorly written).
Here is the link to that C code:ftp://ftp.software.ibm.com/software/...0/4610micr.zip
I've even tried using boost to generate a Python module, but that
didn't go well, and in the end is not going to be a solution for me
anyway.. really need access to the Python source.
Any help at all would be appreciated,
-mkp
Is there a spec somewhere for this data? Googling for "MICR data
format specification" and similar gives links to specifications for
the MICR character *fonts*, but not for the data content.
And you are right, reverse-engineering this code is more than a 10-
minute exercise. (However, the zip file *does* include a nice set of
test cases, which might be better than the C code as a starting point
for new code.)
-- Paul
On Mar 24, 4:55 pm, "Paul McGuire" <p...@austin.rr .comwrote:
On Mar 24, 2:05 pm, "mkppk" <barnaclej...@g mail.comwrote:
MICR = The line of digits printed using magnetic ink at the bottom of
a check.
Does anyone know of a Python function that has been written to parse a
line of MICR data?
Or, some financial package that may contain such a thing?
Or, in general, where I should be looking when looking for a piece of
Python code that may have already been written by someone?
I'm working on a project that involves a check scanner the produces
the raw MICR line as text.
Now, that raw MICR needs to be parsed for the various pieces of info.
The problem with MICR is that there is no standard layout. There are
some general rules for item placement, but beyond that it is up to the
individual banks to define how they choose to position the
information.
I did find an old C program written by someone at IBM... But I've read
it and it is Not code that would nicely convert to Python (maybe its
all the Python I'm used to, be it seems very poorly written).
Here is the link to that C code:ftp://ftp.software.ibm.com/software/...0/4610micr.zip
I've even tried using boost to generate a Python module, but that
didn't go well, and in the end is not going to be a solution for me
anyway.. really need access to the Python source.
Any help at all would be appreciated,
-mkp
Is there a spec somewhere for this data? Googling for "MICR data
format specification" and similar gives links to specifications for
the MICR character *fonts*, but not for the data content.
And you are right, reverse-engineering this code is more than a 10-
minute exercise. (However, the zip file *does* include a nice set of
test cases, which might be better than the C code as a starting point
for new code.)
-- Paul
Well, the problem is that the "specificat ion" is that "there is no
specification", thats just the way the MICR data line has evolved in
the banking industry unfortunately for us developers.. That being
said, there are obviusly enough banking companies out that with enough
example data to have intelligent parsers that handle all the
variations. And the C program appears to have all that built into it.
Its just that I would rather not reinvent the wheel (or read old C
code)..
So, the search continues..
On Mar 24, 6:52 pm, "mkppk" <barnaclej...@g mail.comwrote:
>
Its just that I would rather not reinvent the wheel (or read old C
code)..
Wouldn't we all!
Here is the basic structure of a pyparsing solution. The parsing part
isn't so bad - the real problem is the awful ParseONUS routine in C.
Plus things are awkward since the C program parses right-to-left and
then reverses all of the found fields, and the parser I wrote works
left-to-right. Still, this grammar does most of the job. I've left
out my port of ParseONUS since it is *so* ugly, and not really part of
the pyparsing example.
-- Paul
from pyparsing import *
# define values for optional fields
NoAmountGiven = ""
NoEPCGiven = ""
NoAuxOnusGiven = ""
# define delimiters
DOLLAR = Suppress("$")
T_ = Suppress("T")
A_ = Suppress("A")
# field definitions
amt = DOLLAR + Word(nums,exact =10) + DOLLAR
onus = Word("012345678 9A- ")
transit = T_ + Word("012345678 9-") + T_
epc = oneOf( list(nums) )
aux_onus = A_ + Word("012345678 9- ") + A_
# validation parse action
def validateTransit Number(t):
transit = t[0]
flds = transit.split("-")
if len(flds) 2:
raise ParseException( 0, "too many dashes in transit number",
0)
if len(flds) == 2:
if len(flds[0]) not in (3,4):
raise ParseException( 0, "invalid dash position in transit
number", 0)
else:
# compute checksum
ti = map(int,transit )
ti.reverse() # original algorithm worked with reversed data
cksum = 3*(ti[8]+ti[5]+ti[2]) + 7*(ti[7]+ti[4]+ti[1]) +
ti[6]+ti[3]+ti[0]
if cksum%10 != 0:
raise ParseException( 0, "transit number failed checksum",
0)
return transit
# define overall MICR format, with results names
micrdata =
Optional(aux_on us,default=NoAu xOnusGiven).set ResultsName("au x_onus") +
\
Optional(epc,de fault=NoEPCGive n).setResultsNa me("epc") +\
transit.setPars eAction(validat eTransitNumber) .setResultsName ("transit")
+ \
onus.setResults Name("onus") + \
Optional(amt,de fault=NoAmountG iven).setResult sName("amt")
+ \
stringEnd
import re
def parseONUS(token s):
tokens["csn"] = ""
tokens["tpc"] = ""
tokens["account"] = ""
tokens["amt"] = tokens["amt"][0]
onus = tokens.onus
# remainder omitted out of respect for newsreaders...
# suffice to say that unspeakable acts are performed on
# onus and aux_onus fields to extract account and
# check numbers
micrdata.setPar seAction(parseO NUS)
testdata = file("checks.cs v").readline s()[1:]
tests = [(flds[1],flds) for flds in map(lambda
l:l.split(","), testdata)]
def verifyResults(r es,csv):
def match(x,y):
print (x==y and "_" or "X"),x,"=", y
Ex,MICR,Bank,St at,Amt,AS,TPC,T S,CSN,CS,ACCT,A S,EPC,ES,ONUS,O S,AUX,AS,Tran,T S
= csv
match(res.amt,A mt)
match(res.accou nt,ACCT)
match(res.csn,C SN)
match(res.onus, ONUS)
match(res.tpc,T PC)
match(res.epc,E PC)
match(res.trans it,Tran)
for t,data in tests:
print t
try:
res = micrdata.parseS tring(t)
print res.dump()
if not(data[0] == "No"):
print "Passed expression that should have failed"
verifyResults(r es,data)
except ParseException, pe:
print "<parse failed%s" % pe.msg
if not(data[0] == "Yes"):
print "Failed expression that should have passed"
print
On Mar 25, 12:30 am, "Paul McGuire" <p...@austin.rr .comwrote:
On Mar 24, 6:52 pm, "mkppk" <barnaclej...@g mail.comwrote:
Its just that I would rather not reinvent the wheel (or read old C
code)..
Wouldn't we all!
Here is the basic structure of a pyparsing solution. The parsing part
isn't so bad - the real problem is the awful ParseONUS routine in C.
Plus things are awkward since the C program parses right-to-left and
then reverses all of the found fields, and the parser I wrote works
left-to-right. Still, this grammar does most of the job. I've left
out my port of ParseONUS since it is *so* ugly, and not really part of
the pyparsing example.
-- Paul
from pyparsing import *
# define values for optional fields
NoAmountGiven = ""
NoEPCGiven = ""
NoAuxOnusGiven = ""
# define delimiters
DOLLAR = Suppress("$")
T_ = Suppress("T")
A_ = Suppress("A")
# field definitions
amt = DOLLAR + Word(nums,exact =10) + DOLLAR
onus = Word("012345678 9A- ")
transit = T_ + Word("012345678 9-") + T_
epc = oneOf( list(nums) )
aux_onus = A_ + Word("012345678 9- ") + A_
# validation parse action
def validateTransit Number(t):
transit = t[0]
flds = transit.split("-")
if len(flds) 2:
raise ParseException( 0, "too many dashes in transit number",
0)
if len(flds) == 2:
if len(flds[0]) not in (3,4):
raise ParseException( 0, "invalid dash position in transit
number", 0)
else:
# compute checksum
ti = map(int,transit )
ti.reverse() # original algorithm worked with reversed data
cksum = 3*(ti[8]+ti[5]+ti[2]) + 7*(ti[7]+ti[4]+ti[1]) +
ti[6]+ti[3]+ti[0]
if cksum%10 != 0:
raise ParseException( 0, "transit number failed checksum",
0)
return transit
# define overallMICRform at, with results names
micrdata =
Optional(aux_on us,default=NoAu xOnusGiven).set ResultsName("au x_onus") +
\
Optional(epc,de fault=NoEPCGive n).setResultsNa me("epc") +\
transit.setPars eAction(validat eTransitNumber) .setResultsName ("transit")
+ \
onus.setResults Name("onus") + \
Optional(amt,de fault=NoAmountG iven).setResult sName("amt")
+ \
stringEnd
import re
def parseONUS(token s):
tokens["csn"] = ""
tokens["tpc"] = ""
tokens["account"] = ""
tokens["amt"] = tokens["amt"][0]
onus = tokens.onus
# remainder omitted out of respect for newsreaders...
# suffice to say that unspeakable acts are performed on
# onus and aux_onus fields to extract account and
# check numbers
micrdata.setPar seAction(parseO NUS)
testdata = file("checks.cs v").readline s()[1:]
tests = [(flds[1],flds) for flds in map(lambda
l:l.split(","), testdata)]
def verifyResults(r es,csv):
def match(x,y):
print (x==y and "_" or "X"),x,"=", y
Ex,MICR,Bank,St at,Amt,AS,TPC,T S,CSN,CS,ACCT,A S,EPC,ES,ONUS,O S,AUX,AS,Tran,T S
= csv
match(res.amt,A mt)
match(res.accou nt,ACCT)
match(res.csn,C SN)
match(res.onus, ONUS)
match(res.tpc,T PC)
match(res.epc,E PC)
match(res.trans it,Tran)
for t,data in tests:
print t
try:
res = micrdata.parseS tring(t)
print res.dump()
if not(data[0] == "No"):
print "Passed expression that should have failed"
verifyResults(r es,data)
except ParseException, pe:
print "<parse failed%s" % pe.msg
if not(data[0] == "Yes"):
print "Failed expression that should have passed"
print
Great, thanks for taking a look Paul. I had never tried to use
pyparsing before. Yea, the ONUS field is crazy, don't know why there
is no standard for it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: anton muhin |
last post by:
Hello, everybody!
Can someone give an overview of existing Python parser generators?
I played with TPG and like it a lot. However, I'd like to know more
about alternatives. Google shows several options: PyLR, DParser, etc.
I'm not intrested in ultra-speed: TPG although claims to be not
lighting-quick seems quick enough for my needs, I'm rather looking for
convinience and expressivness.
|
by: Leif K-Brooks |
last post by:
Has anyone ever tried implementing a simple unstructured BASIC dialect
in Python? I'm getting interested in language implementation, and
looking at a reasonably simple example like that could be pretty
interesting.
|
by: tuxlover |
last post by:
Hello everyone
I have to write a verilog parser in python for a class project. I was
wondering if all you folks could advise me on choosing the right python
parser module. I am not comfortable with lex/yacc and as a result find
myself strugging with any module which use lex/yacc syntax/philosophy.
pyparser looks good to me, but before I dive into it, I would really
appreciate feedback from members of this group
Thanks
|
by: Extremest |
last post by:
I know there are ways to make this a lot faster. Any
newsreader does this in seconds. I don't know how they do
it and I am very new to c#. If anyone knows a faster way
please let me know. All I am doing is quering the db for
all the headers for a certain group and then going through
them to find all the parts of each post. I only want ones
that are complete. Meaning all segments for that one file
posted are there.
using System;
|
by: Joel Hedlund |
last post by:
Hi!
I have a possibly dumb question about imports. I've written two python
modules:
parser.py
------------------------------------
class Parser(object):
"my parser"
------------------------------------
| |
by: Paddy3118 |
last post by:
This month there was/is a 1000+ long thread called:
"merits of Lisp vs Python"
In comp.lang.lisp.
If you followed even parts of the thread, AND previously
used only one of the languages AND (and this is the
crucial bit), were persuaded to have a more positive view
of the other language; (deep breath, this is a long, as
well as grammatically incorrect sentence), THEN WHY NOT
POST ON WHAT ARGUMENTS PERSUADED YOU.
|
by: Blubaugh, David A. |
last post by:
Pauli,
Yes, I am utilizing the windows environment. I cannot install f2py.
I obtain the following error when I try to execute the setup.py file
within the f2py folder located within the numpy master folder:
Warning: Assuming default configuration
|
by: Robert Kern |
last post by:
dudeja.rajat@gmail.com wrote:
There are a couple of ways to do #3. One would be to use the difflib module from
the standard library. The Differ.compare() method will give you a sequence of
lines with prefixed character saying whether the line was the same in both
files, deleted from the first or added by the second. Lines that are recognized
as having changed (rather than just being deleted then readded with
modifications) are also...
|
by: Kirill Simonov |
last post by:
========================
Announcing PyYAML-3.06
========================
A new bug fix release of PyYAML is now available:
http://pyyaml.org/wiki/PyYAML
Changes
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |