37 lines
1.1 KiB
Python
Executable file
37 lines
1.1 KiB
Python
Executable file
#!/usr/bin/python
|
|
from pyaccuwage.parser import RecordBuilder
|
|
from pyaccuwage.pdfextract import PDFRecordFinder
|
|
import argparse
|
|
import sys
|
|
import os
|
|
|
|
parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.")
|
|
parser.add_argument("-i", "--input", nargs=1, required=True, metavar="file", type=argparse.FileType('r'), help="Source PDF file, ie: p1220.pdf")
|
|
parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true")
|
|
|
|
args = parser.parse_args()
|
|
|
|
def generate_imports():
|
|
return "\n".join([
|
|
"from pyaccuwage import model",
|
|
"from pyaccuwage.fields import *",
|
|
"",
|
|
"",
|
|
])
|
|
|
|
def generate_class_begin(name):
|
|
return "class %s(mode.Model):\n" % name
|
|
|
|
if args.full:
|
|
sys.stdout.write(generate_imports())
|
|
|
|
source_file = os.path.abspath(args.input[0].name)
|
|
|
|
doc = PDFRecordFinder(source_file)
|
|
records = doc.records()
|
|
builder = RecordBuilder()
|
|
for rec in records:
|
|
print 'name', rec[0]
|
|
for field in builder.load(map(lambda x:x.tuple, rec[1][1:])):
|
|
print field
|
|
|