albmarin / badx12 Goto Github PK
View Code? Open in Web Editor NEWA Python Library for parsing ANSI ASC X12 files.
License: MIT License
A Python Library for parsing ANSI ASC X12 files.
License: MIT License
I am pretty excited about the start here. I having been tasked with working on parsing a different EDI transaction type (417). What I am thinking is some sort of configuration data that can be used to define the segments a transaction type would be looking for.
I am digging through the code and have a few other questions, as well. For example, I do not have ~ for each segment. How do I set this to simply EOL? I have to admit I am pretty green in use of objects in Python, but I am willing to put in some work and energy to make this a more powerful EDI parsing tool.
I am trying to convert an edi data to json data.
the process actually ran for small files.
badx12 parse "ARDEN21999716673775ad3node1.edi" -e JSON -o "output"
###What I got.
'''
2019-05-20 12:57:39,242|ERROR|init.py:44|ARDEN21999716673775ad3node1.edi contains the following errors. Issues: ['The Number of Transaction Sets in GE01 value of 2 does not match the parsed count of 1', 'The Number of Transaction Sets in GE01 value of 2 does not match the parsed count of 1', 'The Number of Included Groups in IEA01 value of 1 does not match the parsed count of 2']
'''
The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.
The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.
Trying to convert EDI to JSON format
I get this below error
badx12 parse medline867s_1.prn
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/badx12", line 8, in
sys.exit(cli())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 764, in call
return self.main(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/commands/parse/init.py", line 40, in parse
report = document.validate()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/document.py", line 60, in validate
self.interchange.validate(report)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/utils/interchange.py", line 24, in validate
self._validate_group_count(report)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/utils/interchange.py", line 48, in _validate_group_count
if int(self.trailer.iea01.content) != len(self.groups):
ValueError: invalid literal for int() with base 10: ''
I ran the below command
$ badx12 parse medline867s_1.prn
Any help is really appreciated. Thanks in advance.
I'm trying to parse an incoming X12 (834) document. The error is an IndexError but the actual issue seems to be that this file is using a newline character as the segment terminator but newlines are stripped in the "_validate_document" method that is run prior to the parsing step.
There seems to be some discussion on weather or not newline characters are valid segment terminators: kputnam/stupidedi#106
I've gotten things working for me by changing the return statement of the _validate_document method from "return document.replace("\n", "").strip()" to "return document" but I'm not sure if that will change things for other use cases.
I have a small test script to start understanding how to use the library:
from badx12 import Parser
parser = Parser()
document = parser.parse_document("test_file.834")
File "t.py", line 4, in <module>
document = parser.parse_document("test_file.834")
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 37, in parse_document
self._separate_and_route_segments()
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 101, in _separate_and_route_segments
self._route_segment_to_parser(segment)
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 114, in _route_segment_to_parser
self._parse_transaction_set_header(segment)
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 193, in _parse_transaction_set_header
self._parse_segment(transaction_header, header_field_list)
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 134, in _parse_segment
raise e
File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 129, in _parse_segment
segment.fields[index].content = value
IndexError: list index out of range
import badx12
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python310\lib\site-packages\badx12\__init__.py", line 6, in <module>
from .__main__ import cli
File "C:\Python310\lib\site-packages\badx12\__main__.py", line 10, in <module>
from .common.click import add_commands
File "C:\Python310\lib\site-packages\badx12\common\click.py", line 2, in <module>
from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Python310\lib\collections\__init__.py)
The Iterable abstract class was removed from collections in Python 3.10. See the deprecation note in the 3.9 collections docs. In the section Removed of the 3.10 docs, the item
``
Remove deprecated aliases to Collections Abstract Base Classes from the collections module. (Contributed by Victor Stinner in bpo-37324.)
I tried converting edi files to json via command line, as documented. However, badx12 gave my an error.
cd ~/files/badx12
badx12 parse "./1.edi"
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/badx12", line 7, in <module>
from badx12.__main__ import cli
File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/__init__.py", line 4, in <module>
from .document import EDIDocument
File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/document.py", line 3, in <module>
from badx12.utils import Interchange
File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/utils/__init__.py", line 1, in <module>
from .element import Element
File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/utils/element.py", line 41
msg=f"Field {self.name} is too short. Found {content_length} characters, expected "
^
SyntaxError: invalid syntax
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.