Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/update
diff options
context:
space:
mode:
Diffstat (limited to 'update')
-rwxr-xr-xupdate/gs1_ai.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/update/gs1_ai.py b/update/gs1_ai.py
index b642469..29e2ab6 100755
--- a/update/gs1_ai.py
+++ b/update/gs1_ai.py
@@ -2,7 +2,7 @@
# update/gs1_ai.py - script to get GS1 application identifiers
#
-# Copyright (C) 2019-2023 Arthur de Jong
+# Copyright (C) 2019-2024 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -45,13 +45,19 @@ def fetch_ais():
response = requests.get(download_url, headers=headers, timeout=30)
document = lxml.html.document_fromstring(response.content)
element = document.findall('.//script[@type="application/ld+json"]')[0]
- for entry in json.loads(element.text)['@graph']:
- yield (
- entry['skos:prefLabel'].strip(), # AI
- entry['gs1meta:formatAIvalue'].strip()[3:], # format
- entry['gs1meta:requiresFNC1'], # require FNC1
- [x['@value'] for x in entry['schema:name'] if x['@language'] == 'en'][0].strip(),
- [x['@value'] for x in entry['schema:description'] if x['@language'] == 'en'][0].strip())
+ data = json.loads(element.text)
+ for entry in data['applicationIdentifiers']:
+ if 'applicationIdentifier' in entry:
+ ai = entry['applicationIdentifier'].strip()
+ formatstring = entry['formatString'].strip()
+ if formatstring.startswith(f'N{len(ai)}+'):
+ formatstring = formatstring[3:]
+ yield (
+ ai,
+ formatstring,
+ entry['fnc1required'],
+ entry['label'].strip(),
+ entry['description'].strip())
def group_ai_ranges():