1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 12:43:35 +03:00

feat(package/trend): simple GitHub module results

This commit is contained in:
Louistiti 2019-03-24 15:25:47 +08:00
parent 14de24f6dd
commit 5baec07455
4 changed files with 23 additions and 11 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "leon",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "leon",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Server, packages and web app of the Leon personal assistant",
"author": {
"name": "Louis Grenard",

View File

@ -1,15 +1,18 @@
{
"github": {
"reaching": [
"I'm reaching the GitHub trends..."
"I'm reaching the GitHub trends...",
"I'm finding what's trending on GitHub...",
"Let me find it for you...",
"Let me tell you in a second..."
],
"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."
],
"test": [
"Here it is: <a href=\"%url%\">%name%</a>"
"simple": [
"%rank%. <a href=\"%repository_url%\" target=\"_blank\">%repository_name%</a> created by <a href=\"%author_url%\" target=\"_blank\">%author_username%</a>."
]
},
"producthunt": {

View File

@ -43,14 +43,23 @@ def github(string, entities):
r = utils.http('GET', 'https://github.com/trending')
soup = BeautifulSoup(r.text, features='html.parser')
limit = 5
reponames = soup.select('.repo-list h3', limit=limit)
authornames = ''
elements = soup.select('.repo-list li', limit=limit)
authors = soup.select('.repo-list img')
# print('reponames', reponames)
# print('authornames', authornames)
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
}
)
)
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))
utils.output('inter', 'test', utils.translate('test', { 'url': 'https://getleon.ai', 'name': 'getleon.ai' }))
return utils.output('end', 'done')