Skip to content

Commit

Permalink
feat(package/trend): format GitHub results in one message
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Mar 24, 2019
1 parent 5baec07 commit 9d026b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
30 changes: 25 additions & 5 deletions packages/trend/data/answers/en.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
{
"github": {
"reaching": [
"I'm reaching the GitHub trends...",
"I'm finding what's trending on GitHub...",
"I'm on it...",
"I'm reaching GitHub...",
"Wait a second please...",
"Let me find it for you...",
"Let me tell you in a second..."
"Let me tell you in a second...",
"Let me reach GitHub..."
],
"today": [
"Here are the %limit% latest GitHub trends of today:<br><br><ul>%result%</ul>"
],
"week": [
"Here are the %limit% latest GitHub trends of this week:"
],
"month": [
"Here are the %limit% latest GitHub trends of this month:"
],
"today_with_tech": [
"Here are the %limit% latest GitHub trends of today for the %tech% technology:"
],
"week_with_tech": [
"Here are the %limit% latest GitHub trends of this week for the %tech% technology:"
],
"month_with_tech": [
"Here are the %limit% latest GitHub trends of this month for the %tech% technology:"
],
"unreachable": [
"GitHub is unreachable for the moment, please retry later.",
"I'm having difficulties to reach GitHub, please retry later.",
"GitHub seems to be down, please try again later."
],
"simple": [
"%rank%. <a href=\"%repository_url%\" target=\"_blank\">%repository_name%</a> created by <a href=\"%author_url%\" target=\"_blank\">%author_username%</a>."
"list_element": [
"<li>#%rank%. <a href=\"%repository_url%\" target=\"_blank\">%repository_name%</a> created by <a href=\"%author_url%\" target=\"_blank\">%author_username%</a>.</li>"
]
},
"producthunt": {
Expand Down
21 changes: 13 additions & 8 deletions packages/trend/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,26 @@ def github(string, entities):
limit = 5
elements = soup.select('.repo-list li', limit=limit)
authors = soup.select('.repo-list img')
result = ''

for i, element in enumerate(elements):
repository = element.h3.get_text(strip=True).replace(' ', '')
author = element.img.get('alt')[1:]

utils.output('inter', 'simple', utils.translate('simple', {
'rank': i + 1,
'repository_url': 'https://github.com/' + repository,
'repository_name': repository,
'author_url': 'https://github.com/' + author,
'author_username': author
result += utils.translate('list_element', {
'rank': i + 1,
'repository_url': 'https://github.com/' + repository,
'repository_name': repository,
'author_url': 'https://github.com/' + author,
'author_username': author
}
)

utils.output('end', 'done', utils.translate('today', {
'limit': limit,
'result': result
}
)
)
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))

return utils.output('end', 'done')
2 changes: 1 addition & 1 deletion test/json/punctuation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('punctuation', () => {
const rootFolders = [
'packages'
]
const punctuations = ['.', ';', ':', '?', '!']
const punctuations = ['.', ';', ':', '?', '!', '>']
const findPunctuation = s => punctuations.includes(s[s.length - 1])
const findString = (iterable) => {
const keys = Object.keys(iterable)
Expand Down

0 comments on commit 9d026b9

Please sign in to comment.