-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
running the example outputs nothing #62
Comments
python-3.11.4 |
Hey, CI tests against the latest 3.11, therefore 3.11.4 should be fine. Could you format your snippet - I will try to take a look at this, tomorrow. |
Yes sorry for the formatting, the code is here https://github.com/nerdocs/pydifact under usage. The first example. |
No worries.... :) So, your python 3.11.4 should work with pydifact but the example is a bit misleading: A message is enclosed by a UNH-segment as header and a UNT-segment as footer, the segments of a message are all the segments in between those two (see the Message class. Therefore, the EDI in the string has no segments. You could verify this by replacing it with the following: from pydifact.segmentcollection import Interchange
interchange = Interchange.from_str(
"UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'MSG+1:45'IFT+3+XYZCOMPANY AVAILABILITY'ERC+A7V:1:AMD'UNT+5+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
for segment in message.segments:
print("Segment tag: {}, content: {}".format(segment.tag, segment.elements)) This would output:
This is unfavorable first example so I have put up a PR to fix this. Thank you for pointing this out! |
Thank you. Apparently there are some syntax checks, just one UNH per message for example. But what about DTM:137999 Segments - they are parsed as well. Is there a way to provide a shema file? And what about min/max values for DTM :137 fields (dont know the specifications for EAN007). But lets assume its allowed one time - can pydifact catch that and throw an error on a second match? Test Message: |
The current checks only verify that objects (segments, messages and interchanges…) can be correctly constructed. As a UNH-segment indicates the beginning of a message, pydifact expects that the previous message is closed with a UNT-footer. So you can think of the current checks as general syntax assurances. A nested validation like is-this-a-valid-datetime or for formats and schemas is currently not implemented. Although there is a PR #37 where others tried to add a mapping-feature. Another solution could be implementing your own schema validator or/and Segments. Pydifact provides some basic validators and a class CustomDTM(Segment):
tag = "DTM"
__omitted__ = False
def validate(self) -> bool:
# add your business logic here
#
# is a valid date etc. .. See the implementations of API and Segment But be aware that now all segments with the DTM-tag are going to be instances of |
Hi,
this is the example, changed sligtly, it shows the input message as output. But the for loop outputs nothing?
Do i maybe need a older python for this?
cat first.py
from pydifact.segmentcollection import Interchange
#interchange = Interchange.from_file("./tests/data/order.edi")
interchange2 = Interchange.from_str(
"UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'"
)
for message in interchange2.get_messages():
print(message)
print(message.segments)
for segment in message.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
The text was updated successfully, but these errors were encountered: