mirror of https://gitlab.com/bashrc2/epicyon
Allow for non-food items in catalog
parent
0bfe005b43
commit
206aaa8940
23
shares.py
23
shares.py
|
@ -159,7 +159,9 @@ def _getshareDfcId(baseDir: str, systemLanguage: str,
|
||||||
See https://github.com/datafoodconsortium/ontology
|
See https://github.com/datafoodconsortium/ontology
|
||||||
"""
|
"""
|
||||||
if translate['food'] not in itemCategory.lower():
|
if translate['food'] not in itemCategory.lower():
|
||||||
return ''
|
itemType = itemType.replace(' ', '_')
|
||||||
|
itemType = itemType.replace('.', '')
|
||||||
|
return 'epicyon#' + itemType
|
||||||
if not dfcIds:
|
if not dfcIds:
|
||||||
dfcIds = _loadDfcIds(baseDir, systemLanguage)
|
dfcIds = _loadDfcIds(baseDir, systemLanguage)
|
||||||
if not dfcIds:
|
if not dfcIds:
|
||||||
|
@ -193,6 +195,11 @@ def _getshareTypeFromDfcId(dfcUri: str, dfcIds: {}) -> str:
|
||||||
based upon productTypes ontology.
|
based upon productTypes ontology.
|
||||||
See https://github.com/datafoodconsortium/ontology
|
See https://github.com/datafoodconsortium/ontology
|
||||||
"""
|
"""
|
||||||
|
if dfcUri.startswith('epicyon#'):
|
||||||
|
itemType = dfcUri.split('#')[1]
|
||||||
|
itemType = itemType.replace('_', ' ')
|
||||||
|
return itemType
|
||||||
|
|
||||||
for name, uri in dfcIds.items():
|
for name, uri in dfcIds.items():
|
||||||
if uri.endswith('#' + dfcUri):
|
if uri.endswith('#' + dfcUri):
|
||||||
return name
|
return name
|
||||||
|
@ -834,12 +841,15 @@ def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str,
|
||||||
expireDateStr = expireDate.strftime("%Y-%m-%dT%H:%M:%SZ")
|
expireDateStr = expireDate.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
shareId = getValidSharedItemID(owner, item['displayName'])
|
shareId = getValidSharedItemID(owner, item['displayName'])
|
||||||
dfcId = item['dfcId'].split('#')[1]
|
if item['dfcId'].startswith('epicyon#'):
|
||||||
|
dfcId = "epicyon:" + item['dfcId'].split('#')[1]
|
||||||
|
else:
|
||||||
|
dfcId = "dfc-pt:" + item['dfcId'].split('#')[1]
|
||||||
priceStr = item['itemPrice'] + ' ' + item['itemCurrency']
|
priceStr = item['itemPrice'] + ' ' + item['itemCurrency']
|
||||||
catalogItem = {
|
catalogItem = {
|
||||||
"@id": shareId,
|
"@id": shareId,
|
||||||
"@type": "DFC:SuppliedProduct",
|
"@type": "DFC:SuppliedProduct",
|
||||||
"DFC:hasType": "dfc-pt:" + dfcId,
|
"DFC:hasType": dfcId,
|
||||||
"DFC:startDate": item['published'],
|
"DFC:startDate": item['published'],
|
||||||
"DFC:expiryDate": expireDateStr,
|
"DFC:expiryDate": expireDateStr,
|
||||||
"DFC:quantity": item['itemQty'],
|
"DFC:quantity": item['itemQty'],
|
||||||
|
@ -918,12 +928,15 @@ def sharesCatalogEndpoint(baseDir: str, httpPrefix: str,
|
||||||
expireDateStr = expireDate.strftime("%Y-%m-%dT%H:%M:%SZ")
|
expireDateStr = expireDate.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
shareId = getValidSharedItemID(owner, item['displayName'])
|
shareId = getValidSharedItemID(owner, item['displayName'])
|
||||||
dfcId = item['dfcId'].split('#')[1]
|
if item['dfcId'].startswith('epicyon#'):
|
||||||
|
dfcId = "epicyon:" + item['dfcId'].split('#')[1]
|
||||||
|
else:
|
||||||
|
dfcId = "dfc-pt:" + item['dfcId'].split('#')[1]
|
||||||
priceStr = item['itemPrice'] + ' ' + item['itemCurrency']
|
priceStr = item['itemPrice'] + ' ' + item['itemCurrency']
|
||||||
catalogItem = {
|
catalogItem = {
|
||||||
"@id": shareId,
|
"@id": shareId,
|
||||||
"@type": "DFC:SuppliedProduct",
|
"@type": "DFC:SuppliedProduct",
|
||||||
"DFC:hasType": "dfc-pt:" + dfcId,
|
"DFC:hasType": dfcId,
|
||||||
"DFC:startDate": item['published'],
|
"DFC:startDate": item['published'],
|
||||||
"DFC:expiryDate": expireDateStr,
|
"DFC:expiryDate": expireDateStr,
|
||||||
"DFC:quantity": item['itemQty'],
|
"DFC:quantity": item['itemQty'],
|
||||||
|
|
Loading…
Reference in New Issue