mirror of https://gitlab.com/bashrc2/epicyon
More general list of shared item categories
parent
5d54f41533
commit
d0dc6a07a0
17
shares.py
17
shares.py
|
@ -35,18 +35,13 @@ from utils import removeDomainPort
|
|||
from utils import isAccountDir
|
||||
from utils import acctDir
|
||||
from utils import isfloat
|
||||
from utils import getCategoryTypes
|
||||
from media import processMetaData
|
||||
from filters import isFilteredGlobally
|
||||
from siteactive import siteIsActive
|
||||
from content import getPriceFromString
|
||||
|
||||
|
||||
def _dfcProductTypes() -> []:
|
||||
# this list should match the ontology json files
|
||||
# eg. ontology/foodTypes.json
|
||||
return ['food', 'tool', 'clothes', 'medical']
|
||||
|
||||
|
||||
def _loadDfcIds(baseDir: str, systemLanguage: str,
|
||||
productType: str) -> {}:
|
||||
"""Loads the product types ontology
|
||||
|
@ -168,13 +163,14 @@ def _addShareDurationSec(duration: str, published: int) -> int:
|
|||
return 0
|
||||
|
||||
|
||||
def _dfcProductTypeFromCategory(itemCategory: str, translate: {}) -> str:
|
||||
def _dfcProductTypeFromCategory(baseDir: str,
|
||||
itemCategory: str, translate: {}) -> str:
|
||||
"""Does the shared item category match a DFC product type?
|
||||
If so then return the product type.
|
||||
This will be used to select an appropriate ontology file
|
||||
such as ontology/foodTypes.json
|
||||
"""
|
||||
productTypesList = _dfcProductTypes()
|
||||
productTypesList = getCategoryTypes(baseDir)
|
||||
categoryLower = itemCategory.lower()
|
||||
for productType in productTypesList:
|
||||
if translate.get(productType):
|
||||
|
@ -195,7 +191,8 @@ def _getshareDfcId(baseDir: str, systemLanguage: str,
|
|||
"""
|
||||
# does the category field match any prodyct type ontology
|
||||
# files in the ontology subdirectory?
|
||||
matchedProductType = _dfcProductTypeFromCategory(itemCategory, translate)
|
||||
matchedProductType = \
|
||||
_dfcProductTypeFromCategory(baseDir, itemCategory, translate)
|
||||
if not matchedProductType:
|
||||
itemType = itemType.replace(' ', '_')
|
||||
itemType = itemType.replace('.', '')
|
||||
|
@ -1452,7 +1449,7 @@ def _dfcToSharesFormat(catalogJson: {},
|
|||
sharesJson = {}
|
||||
|
||||
dfcIds = {}
|
||||
productTypesList = _dfcProductTypes()
|
||||
productTypesList = getCategoryTypes(baseDir)
|
||||
for productType in productTypesList:
|
||||
dfcIds[productType] = _loadDfcIds(baseDir, systemLanguage, productType)
|
||||
|
||||
|
|
4
tests.py
4
tests.py
|
@ -42,6 +42,7 @@ from follow import clearFollowers
|
|||
from follow import sendFollowRequestViaServer
|
||||
from follow import sendUnfollowRequestViaServer
|
||||
from siteactive import siteIsActive
|
||||
from utils import getCategoryTypes
|
||||
from utils import getSupportedLanguages
|
||||
from utils import setConfigParam
|
||||
from utils import isGroupActor
|
||||
|
@ -5190,7 +5191,8 @@ def _testGetPriceFromString() -> None:
|
|||
|
||||
|
||||
def _translateOntology() -> None:
|
||||
ontologyTypes = ('food', 'clothes', 'tool', 'medical')
|
||||
baseDir = os.getcwd()
|
||||
ontologyTypes = getCategoryTypes(baseDir)
|
||||
url = 'https://translate.astian.org'
|
||||
apiKey = None
|
||||
ltLangList = libretranslateLanguages(url, apiKey)
|
||||
|
|
16
utils.py
16
utils.py
|
@ -2810,3 +2810,19 @@ def getSupportedLanguages(baseDir: str) -> []:
|
|||
languagesStr.append(lang)
|
||||
break
|
||||
return languagesStr
|
||||
|
||||
|
||||
def getCategoryTypes(baseDir: str) -> []:
|
||||
"""Returns the list of ontologies
|
||||
"""
|
||||
ontologyDir = baseDir + '/ontology'
|
||||
categories = []
|
||||
for subdir, dirs, files in os.walk(ontologyDir):
|
||||
for f in files:
|
||||
if not f.endswith('.json'):
|
||||
continue
|
||||
ontologyFilename = f.split('.')[0]
|
||||
if 'Types' in ontologyFilename:
|
||||
categories.append(ontologyFilename.replace('Types', ''))
|
||||
break
|
||||
return categories
|
||||
|
|
|
@ -15,6 +15,7 @@ from utils import getMediaFormats
|
|||
from utils import getConfigParam
|
||||
from utils import acctDir
|
||||
from utils import getCurrencies
|
||||
from utils import getCategoryTypes
|
||||
from webapp_utils import getBannerFile
|
||||
from webapp_utils import htmlHeaderWithExternalStyle
|
||||
from webapp_utils import htmlFooter
|
||||
|
@ -363,7 +364,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
|
|||
extraFields += '<br>' + \
|
||||
editTextField(translate['Type of shared item. eg. hat'] + ':',
|
||||
'itemType', '', '', True)
|
||||
categoryTypes = ("food", "clothes", "tool", "medical")
|
||||
categoryTypes = getCategoryTypes()
|
||||
catStr = translate['Category of shared item. eg. clothing']
|
||||
extraFields += '<label class="labels">' + catStr + '</label><br>\n'
|
||||
|
||||
|
|
Loading…
Reference in New Issue