Check for food category before assigning dfc id

merge-requests/30/head
Bob Mottram 2021-07-24 16:05:21 +01:00
parent f1d42b62db
commit 723e6e7a5e
21 changed files with 50 additions and 26 deletions

View File

@ -13665,7 +13665,8 @@ class PubServer(BaseHTTPRequestHandler):
durationStr, durationStr,
self.server.debug, self.server.debug,
city, city,
self.server.systemLanguage) self.server.systemLanguage,
self.server.translate)
if filename: if filename:
if os.path.isfile(filename): if os.path.isfile(filename):
os.remove(filename) os.remove(filename)

View File

@ -2332,7 +2332,7 @@ if args.testdata:
"mechanical", "mechanical",
"City", "City",
"2 months", "2 months",
debug, city, args.language) debug, city, args.language, {})
addShare(baseDir, addShare(baseDir,
httpPrefix, nickname, domain, port, httpPrefix, nickname, domain, port,
"witch hat", "witch hat",
@ -2342,7 +2342,7 @@ if args.testdata:
"clothing", "clothing",
"City", "City",
"3 months", "3 months",
debug, city, args.language) debug, city, args.language, {})
deleteAllPosts(baseDir, nickname, domain, 'inbox') deleteAllPosts(baseDir, nickname, domain, 'inbox')
deleteAllPosts(baseDir, nickname, domain, 'outbox') deleteAllPosts(baseDir, nickname, domain, 'outbox')

View File

@ -549,7 +549,8 @@ def postMessageToOutbox(session, translate: {},
if debug: if debug:
print('DEBUG: handle share uploads') print('DEBUG: handle share uploads')
outboxShareUpload(baseDir, httpPrefix, postToNickname, domain, outboxShareUpload(baseDir, httpPrefix, postToNickname, domain,
port, messageJson, debug, city, systemLanguage) port, messageJson, debug, city,
systemLanguage, translate)
if debug: if debug:
print('DEBUG: handle undo share uploads') print('DEBUG: handle undo share uploads')

View File

@ -139,11 +139,15 @@ def _addShareDurationSec(duration: str, published: str) -> int:
return 0 return 0
def _getshareDfcId(baseDir: str, systemLanguage: str, itemType: str) -> str: def _getshareDfcId(baseDir: str, systemLanguage: str,
itemType: str, itemCategory: str,
translate: {}) -> str:
"""Attempts to obtain a DFC Id for the shared item, """Attempts to obtain a DFC Id for the shared item,
based upon productTypes ontology. based upon productTypes ontology.
See https://github.com/datafoodconsortium/ontology See https://github.com/datafoodconsortium/ontology
""" """
if translate['food'] not in itemCategory.lower():
return ''
dfcIds = _loadDfcIds(baseDir, systemLanguage) dfcIds = _loadDfcIds(baseDir, systemLanguage)
if not dfcIds: if not dfcIds:
return '' return ''
@ -176,7 +180,7 @@ def addShare(baseDir: str,
displayName: str, summary: str, imageFilename: str, displayName: str, summary: str, imageFilename: str,
itemQty: int, itemType: str, itemCategory: str, location: str, itemQty: int, itemType: str, itemCategory: str, location: str,
duration: str, debug: bool, city: str, duration: str, debug: bool, city: str,
systemLanguage: str) -> None: systemLanguage: str, translate: {}) -> None:
"""Adds a new share """Adds a new share
""" """
sharesFilename = acctDir(baseDir, nickname, domain) + '/shares.json' sharesFilename = acctDir(baseDir, nickname, domain) + '/shares.json'
@ -189,7 +193,8 @@ def addShare(baseDir: str,
durationSec = _addShareDurationSec(duration, published) durationSec = _addShareDurationSec(duration, published)
itemID = getValidSharedItemID(displayName) itemID = getValidSharedItemID(displayName)
dfcId = _getshareDfcId(baseDir, systemLanguage, itemType) dfcId = _getshareDfcId(baseDir, systemLanguage,
itemType, itemCategory, translate)
# has an image for this share been uploaded? # has an image for this share been uploaded?
imageUrl = None imageUrl = None
@ -603,7 +608,7 @@ def sendUndoShareViaServer(baseDir: str, session,
def outboxShareUpload(baseDir: str, httpPrefix: str, def outboxShareUpload(baseDir: str, httpPrefix: str,
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
messageJson: {}, debug: bool, city: str, messageJson: {}, debug: bool, city: str,
systemLanguage: str) -> None: systemLanguage: str, translate: {}) -> None:
""" When a shared item is received by the outbox from c2s """ When a shared item is received by the outbox from c2s
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
@ -658,7 +663,7 @@ def outboxShareUpload(baseDir: str, httpPrefix: str,
messageJson['object']['itemCategory'], messageJson['object']['itemCategory'],
messageJson['object']['location'], messageJson['object']['location'],
messageJson['object']['duration'], messageJson['object']['duration'],
debug, city, systemLanguage) debug, city, systemLanguage, translate)
if debug: if debug:
print('DEBUG: shared item received via c2s') print('DEBUG: shared item received via c2s')

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "أعلمني عندما ينشر الحساب هذا", "Notify me when this account posts": "أعلمني عندما ينشر الحساب هذا",
"Languages": "اللغات", "Languages": "اللغات",
"Translated": "تترجم", "Translated": "تترجم",
"Quantity": "كمية" "Quantity": "كمية",
"food": "غذاء"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Aviseu-me quan publiqui aquest compte", "Notify me when this account posts": "Aviseu-me quan publiqui aquest compte",
"Languages": "Idiomes", "Languages": "Idiomes",
"Translated": "Traduït", "Translated": "Traduït",
"Quantity": "Quantitat" "Quantity": "Quantitat",
"food": "menjar"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Rhoi gwybod i mi pan fydd y cyfrifon cyfrif hwn", "Notify me when this account posts": "Rhoi gwybod i mi pan fydd y cyfrifon cyfrif hwn",
"Languages": "Ieithoedd", "Languages": "Ieithoedd",
"Translated": "Chyfieithwyd", "Translated": "Chyfieithwyd",
"Quantity": "Symiau" "Quantity": "Symiau",
"food": "bwyd"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Benachrichtigen Sie mich, wenn dieses Konto postet", "Notify me when this account posts": "Benachrichtigen Sie mich, wenn dieses Konto postet",
"Languages": "Sprachen", "Languages": "Sprachen",
"Translated": "Übersetzt", "Translated": "Übersetzt",
"Quantity": "Menge" "Quantity": "Menge",
"food": "lebensmittel"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Notify me when this account posts", "Notify me when this account posts": "Notify me when this account posts",
"Languages": "Languages", "Languages": "Languages",
"Translated": "Translated", "Translated": "Translated",
"Quantity": "Quantity" "Quantity": "Quantity",
"food": "food"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Notifíqueme cuando se publique esta cuenta", "Notify me when this account posts": "Notifíqueme cuando se publique esta cuenta",
"Languages": "Idiomas", "Languages": "Idiomas",
"Translated": "Traducida", "Translated": "Traducida",
"Quantity": "Cantidad" "Quantity": "Cantidad",
"food": "comida"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Avertissez-moi quand ce compte publie", "Notify me when this account posts": "Avertissez-moi quand ce compte publie",
"Languages": "Langues", "Languages": "Langues",
"Translated": "Traduite", "Translated": "Traduite",
"Quantity": "Quantité" "Quantity": "Quantité",
"food": "aliments"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Cuir in iúl dom nuair a phostófar an cuntas seo", "Notify me when this account posts": "Cuir in iúl dom nuair a phostófar an cuntas seo",
"Languages": "Teangacha", "Languages": "Teangacha",
"Translated": "Aistrithe", "Translated": "Aistrithe",
"Quantity": "Cainníocht" "Quantity": "Cainníocht",
"food": "bia"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "यह खाता पोस्ट होने पर मुझे सूचित करें", "Notify me when this account posts": "यह खाता पोस्ट होने पर मुझे सूचित करें",
"Languages": "बोली", "Languages": "बोली",
"Translated": "अनुवाद", "Translated": "अनुवाद",
"Quantity": "मात्रा" "Quantity": "मात्रा",
"food": "खाना"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Avvisami quando questo account messaggi", "Notify me when this account posts": "Avvisami quando questo account messaggi",
"Languages": "Le lingue", "Languages": "Le lingue",
"Translated": "Tradotto", "Translated": "Tradotto",
"Quantity": "Quantità" "Quantity": "Quantità",
"food": "cibo"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "この口座投稿を通知する", "Notify me when this account posts": "この口座投稿を通知する",
"Languages": "言語", "Languages": "言語",
"Translated": "翻訳", "Translated": "翻訳",
"Quantity": "量" "Quantity": "量",
"food": "食物"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Dema ku ev postên hesabê min agahdar bikin", "Notify me when this account posts": "Dema ku ev postên hesabê min agahdar bikin",
"Languages": "Ziman", "Languages": "Ziman",
"Translated": "Wergerandin", "Translated": "Wergerandin",
"Quantity": "Jimarî" "Quantity": "Jimarî",
"food": "xûrek"
} }

View File

@ -449,5 +449,6 @@
"Notify me when this account posts": "Notify me when this account posts", "Notify me when this account posts": "Notify me when this account posts",
"Languages": "Languages", "Languages": "Languages",
"Translated": "Translated", "Translated": "Translated",
"Quantity": "Quantity" "Quantity": "Quantity",
"food": "food"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Notifique-me quando esta conta posts", "Notify me when this account posts": "Notifique-me quando esta conta posts",
"Languages": "Línguas", "Languages": "Línguas",
"Translated": "Traduzida", "Translated": "Traduzida",
"Quantity": "Quantidade" "Quantity": "Quantidade",
"food": "comida"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Сообщите мне, когда эта учетная запись", "Notify me when this account posts": "Сообщите мне, когда эта учетная запись",
"Languages": "Языки", "Languages": "Языки",
"Translated": "Перевод", "Translated": "Перевод",
"Quantity": "Количество" "Quantity": "Количество",
"food": "еда"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "Nijulishe wakati akaunti hii ya akaunti.", "Notify me when this account posts": "Nijulishe wakati akaunti hii ya akaunti.",
"Languages": "Lugha", "Languages": "Lugha",
"Translated": "Ilitafsiriwa", "Translated": "Ilitafsiriwa",
"Quantity": "Wingi" "Quantity": "Wingi",
"food": "chakula"
} }

View File

@ -453,5 +453,6 @@
"Notify me when this account posts": "此帐户帖子时通知我", "Notify me when this account posts": "此帐户帖子时通知我",
"Languages": "语言", "Languages": "语言",
"Translated": "翻译", "Translated": "翻译",
"Quantity": "数量" "Quantity": "数量",
"food": "食物"
} }