So I'm trying to find all the values of ai = '' in the below given library for gs1. To access that it already has the command:
result = biip.parse("010703206980498815210526100329") result.gs1_message.element_strings
for ex in the below code, I'd like to get all the values where ai = '01', ai ='15' and ai ='10'. After finding these values, I need to make condition for each one of them like: if ai ='01': then something.
But my main concern is how can I access it since its inside GS1ElementString, which is inside ai=GS1ApplicationIdentifier, but I don't want to get this value as here ai = is a string. I need values after that bracket where ai = '01' and then the same for the remaining three GS1ElementString.
[
[**GS1ElementString**(
ai=GS1ApplicationIdentifier(
**ai='01'**,
description='Global Trade Item Number (GTIN)',
data_title='GTIN',
fnc1_required=False,
format='N2 N14',
),
value='07032069804988',
pattern_groups=['07032069804988'],
gln=None,
gtin=Gtin(
value='07032069804988',
format=GtinFormat.GTIN_13,
prefix=GS1Prefix(value='703', usage='GS1 Norway'),
payload='703206980498',
check_digit=8,
packaging_level=None,
),
sscc=None,
date=None,
decimal=None,
money=None,
),
**GS1ElementString**(
ai=GS1ApplicationIdentifier(
**ai='15'**,
description='Best before date (YYMMDD)',
data_title='BEST BEFORE or BEST BY',
fnc1_required=False,
format='N2 N6',
),
value='210526',
pattern_groups=['210526'],
gln=None,
gtin=None,
sscc=None,
date=datetime.date(2021, 5, 26),
decimal=None,
money=None,
),
**GS1ElementString**(
ai=GS1ApplicationIdentifier(
**ai='10'**,
description='Batch or lot number',
data_title='BATCH/LOT',
fnc1_required=True,
format='N2 X..20'
),
value='0329',
pattern_groups=['0329'],
gln=None,
gtin=None,
sscc=None,
date=None,
decimal=None,
money=None,
),]
Here is the link to the biip library documentation for a better understanding: https://biip.readthedocs.io/en/stable/quickstart/ It under Product IDs, expiration dates, and lot numbers
CodePudding user response:
So I was able to do it reading the hovering over the GS1ApplicationIdentifier
function and reading the documentation on PyCharm.
Using this:
i = str(GS1ApplicationIdentifier.extract("01"))
s = ai[1:-1]
--> (01)
--> 01
I easily get the ai
value that I'm interested in. And then using slicing I removed the brackets.