1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-20 06:17:20 +03:00

refactor(skill/product_hunt_trends): from module to skill

This commit is contained in:
louistiti 2022-02-22 09:04:18 +08:00
parent 4029759ba7
commit 131659928e
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
12 changed files with 223 additions and 4 deletions

View File

@ -49,6 +49,11 @@
],
"entitiesType": "builtIn"
},
{
"method": "GET",
"route": "/api/action/news/product_hunt_trends/run",
"params": []
},
{
"method": "POST",
"route": "/api/action/productivity/todo_list/create_list",
@ -133,4 +138,4 @@
"params": []
}
]
}
}

View File

@ -5,7 +5,7 @@
"%limit% tendances GitHub c'est beaucoup, permettez moi de vous donner les 25 tendances à la place."
],
"reaching": [
"Je suis en train d'atteindre GitHub, veuille patienter une seconde...",
"Je suis en train d'atteindre GitHub, veuillez patienter une seconde...",
"Laissez moi atteindre GitHub..."
],
"today": [
@ -41,7 +41,7 @@
"%limit% tendances Product Hunt c'est beaucoup, permettez moi de vous donner les %new_limit% tendances à la place."
],
"reaching": [
"Je suis en train d'atteindre Product Hunt, veuille patienter une seconde...",
"Je suis en train d'atteindre Product Hunt, veuillez patienter une seconde...",
"Laissez moi atteindre Product Hunt..."
],
"today": [

View File

@ -17,7 +17,7 @@
"%limit% tendances GitHub c'est beaucoup, permettez moi de vous donner les 25 tendances à la place."
],
"reaching": [
"Je suis en train d'atteindre GitHub, veuille patienter une seconde...",
"Je suis en train d'atteindre GitHub, veuillez patienter une seconde...",
"Laissez moi atteindre GitHub..."
],
"today": [

View File

@ -0,0 +1,51 @@
{
"actions": {
"run": {
"utterance_samples": [
"What are the trends on Product Hunt?",
"Give me the Product Hunt trends",
"What's trending on Product Hunt?",
"What are the trends on PH?",
"Give me the PH trends",
"What's trending on PH?",
"What's trending on ProductHunt?"
]
}
},
"answers": {
"limit_max": [
"You've asked for too many Product Hunt trends, I'll give you %new_limit% trends instead.",
"%limit% Product Hunt trends is a lot, let me tell you the %new_limit% trends instead."
],
"reaching": [
"I'm reaching Product Hunt, please wait a second...",
"Let me reach Product Hunt..."
],
"today": [
"Here are the %limit% Product Hunt trends of the day:<br><br><ul>%result%</ul>"
],
"specific_day": [
"Here are the %limit% Product Hunt trends for the %date%:<br><br><ul>%result%</ul>"
],
"unreachable": [
"Product Hunt is unreachable for the moment, please retry later.",
"I'm having difficulties to reach Product Hunt, please retry later.",
"Product Hunt seems to be down, please try again later."
],
"list_element": [
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> created by <a href=\"%author_url%\" target=\"_blank\">%author_name%</a> with %votes_nb% votes.</li>"
],
"list_element_with_unknown_maker": [
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> with %votes_nb% votes. There is no information about the maker.</li>",
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> with %votes_nb% votes. I did not find any information about the maker.</li>"
],
"not_found": [
"There is no product on that date.",
"I did not find any product on that date."
],
"invalid_developer_token": [
"Your Product Hunt developer token is invalid. Please provide a valid one by <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">reading this</a>.",
"You did not set a valid Product Hunt developer token. Please set a valid one by <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">reading this</a>."
]
}
}

View File

@ -0,0 +1,50 @@
{
"actions": {
"run": {
"utterance_samples": [
"Quelles sont les tendances sur Product Hunt ?",
"Donne-moi les tendances Product Hunt",
"Qu'est-ce qu'il y a en tendance sur Product Hunt ?",
"Quelles sont les tendances sur PH ?",
"Donne-moi les tendances PH",
"Qu'est-ce qu'il y a en tendance sur PH ?"
]
}
},
"answers": {
"limit_max": [
"Vous demandez beaucoup trop de tendances, laissez moi plutôt vous donner les %new_limit% tendances.",
"%limit% tendances Product Hunt c'est beaucoup, permettez moi de vous donner les %new_limit% tendances à la place."
],
"reaching": [
"Je suis en train d'atteindre Product Hunt, veuillez patienter une seconde...",
"Laissez moi atteindre Product Hunt..."
],
"today": [
"Voici les %limit% dernières tendances Product Hunt du jour :<br><br><ul>%result%</ul>"
],
"specific_day": [
"Voici les %limit% dernières tendances Product Hunt du %date% :<br><br><ul>%result%</ul>"
],
"unreachable": [
"Product Hunt est inaccessible pour le moment, merci de réessayer plus tard.",
"Je rencontre des difficultés pour atteindre Product Hunt, merci de réessayer plus tard.",
"Product Hunt semble ne pas fonctionner correctement, veuillez retenter plus tard."
],
"list_element": [
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> créé par <a href=\"%author_url%\" target=\"_blank\">%author_name%</a> avec %votes_nb% votes.</li>"
],
"list_element_with_unknown_maker": [
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> avec %votes_nb% votes. Il n'y a pas d'information à propos du créateur.</li>",
"<li>#%rank%. <a href=\"%post_url%\" target=\"_blank\">%product_name%</a> avec %votes_nb% votes. Je n'ai trouvé aucune information à propos du créateur.</li>"
],
"not_found": [
"Il n'y a pas de produit à cette date.",
"Je n'ai trouvé aucun produit à cette date."
],
"invalid_developer_token": [
"Votre jeton de développeur Product Hunt est invalide. Merci d'en fournir un valide en <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">lisant ceci</a>.",
"Vous n'avez pas bien configuré votre jeton de développeur Product Hunt. Veuillez en installer un valide en <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">lisant ceci</a>."
]
}
}

View File

@ -0,0 +1,11 @@
{
"name": "Product Hunt Trends",
"bridge": "python",
"version": "1.0.0",
"description": "Get what is trending on Product Hunt.",
"author": {
"name": "Louis Grenard",
"email": "louis.grenard@gmail.com",
"url": "https://github.com/louistiti"
}
}

View File

@ -0,0 +1,94 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
import utils
def run(string, entities):
"""Get the Product Hunt trends"""
# Developer token
developer_token = utils.config('credentials')['developer_token']
# Number of products
limit = 5
# Answer key
answer_key = 'today'
# Day date
day_date = ''
for item in entities:
if item['entity'] == 'number':
limit = item['resolution']['value']
if item['entity'] == 'date':
answer_key = 'specific_day'
if 'strPastValue' in item['resolution']:
day_date = item['resolution']['strPastValue']
else:
day_date = item['resolution']['strValue']
utils.output('inter', 'reaching', utils.translate('reaching'))
try:
url = 'https://api.producthunt.com/v1/posts'
if (day_date != ''):
url = url + '?day=' + day_date
r = utils.http('GET', url, { 'Authorization': 'Bearer ' + developer_token })
response = r.json()
if 'error' in response and response['error'] == 'unauthorized_oauth':
return utils.output('end', 'invalid_developer_token', utils.translate('invalid_developer_token'))
posts = list(enumerate(response['posts']))
result = ''
if len(posts) == 0:
return utils.output('end', 'not_found', utils.translate('not_found'))
if limit > len(posts):
utils.output('inter', 'limit_max', utils.translate('limit_max', {
'limit': limit,
'new_limit': len(posts)
}))
limit = len(posts)
elif limit == 0:
limit = 5
for i, post in posts:
# If the product maker is known
if post['maker_inside']:
author = list(reversed(post['makers']))[0]
result += utils.translate('list_element', {
'rank': i + 1,
'post_url': post['discussion_url'],
'product_name': post['name'],
'author_url': author['profile_url'],
'author_name': author['name'],
'votes_nb': post['votes_count']
}
)
else:
result += utils.translate('list_element_with_unknown_maker', {
'rank': i + 1,
'post_url': post['discussion_url'],
'product_name': post['name'],
'votes_nb': post['votes_count']
}
)
if (i + 1) == limit:
break
return utils.output('end', answer_key, utils.translate(answer_key, {
'limit': limit,
'result': result,
'date': day_date
}
)
)
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))

View File

@ -0,0 +1,8 @@
{
"configurations": {
"options": {},
"credentials": {
"developer_token": "YOUR_DEVELOPER_TOKEN"
}
}
}