Skip to content

Commit

Permalink
Merge pull request #27 from seanap/develop
Browse files Browse the repository at this point in the history
fix(search): 🐛 handle different countries' date structures
fix(search): 🐛 fix score sum if author is missing
  • Loading branch information
djdembeck authored Sep 14, 2021
2 parents ad48e73 + cc79d9c commit 97ea432
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.python-version
.vscode
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"search"
]
}
31 changes: 19 additions & 12 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from update_tools import UpdateTool
from urls import SiteUrl

VERSION_NO = '2021.09.02.1'
VERSION_NO = '2021.09.13.1'

# Starting value for score before deductions are taken.
INITIAL_SCORE = 100
Expand Down Expand Up @@ -370,8 +370,13 @@ def before_xpath(self, ctx, found, html):
'[contains (@class,"releaseDateLabel")]/span'
)
)
datetext = re.sub(r'[^0-9\-]', '', datetext)
date = self.getDateFromString(datetext)

# Handle different date structures
cleaned_datetext = re.search(r'\d{2}[-]\d{2}[-]\d{2}', datetext)
if not cleaned_datetext:
cleaned_datetext = re.search(r'\d{2}[.]\d{2}[.]\d{4}', datetext)

date = self.getDateFromString(cleaned_datetext.group(0))
language = self.getStringContentFromXPath(
r, (
u'div/div/div/div/div/div/span/ul/li'
Expand Down Expand Up @@ -452,17 +457,17 @@ def score_result(self, f, helper, i, info, valid_itemId, year):
all_scores = []

# Album name score
all_scores.append(
self.score_album(helper, title)
)
title_score = self.score_album(helper, title)
if title_score:
all_scores.append(title_score)
# Author name score
all_scores.append(
self.score_author(author, helper)
)
author_score = self.score_author(author, helper)
if author_score:
all_scores.append(author_score)
# Library language score
all_scores.append(
self.score_language(helper, language)
)
lang_score = self.score_language(helper, language)
if lang_score:
all_scores.append(lang_score)

# Because builtin sum() isn't available
sum_scores=lambda numberlist:reduce(lambda x,y:x+y,numberlist,0)
Expand Down Expand Up @@ -839,6 +844,8 @@ def getDateFromString(self, string):
return Datetime.ParseDate(string).date()
except AttributeError:
return None
except ValueError:
return None

def getStringContentFromXPath(self, source, query):
return source.xpath('string(' + query + ')')
Expand Down

0 comments on commit 97ea432

Please # to comment.