mirror of
https://github.com/leon-ai/leon.git
synced 2024-09-19 22:07:10 +03:00
feat(package/trend): basics done on the Product Hunt module
This commit is contained in:
parent
2685cdab07
commit
32cc7dbe36
@ -14,13 +14,29 @@ Grab the GitHub trends repositories according to several options.
|
||||
(en-US) "What's trending on GitHub?"
|
||||
(en-US) "Give me the 4 GitHub trends of this week for the JavaScript language"
|
||||
(en-US) "What's the three GitHub trends of this month?"
|
||||
(fr-FR) "Quelles sont les tendances sur GitHub ?"
|
||||
(fr-FR) "Donne-moi les 4 tendances GitHub de cette semaine pour le langage JavaScript"
|
||||
(fr-FR) "Donne-moi les trois tendances GitHub de ce mois"
|
||||
...
|
||||
```
|
||||
|
||||
### Product Hunt
|
||||
|
||||
WIP...
|
||||
Grab the Product Hunt trends products
|
||||
|
||||
#### Usage
|
||||
|
||||
WIP...
|
||||
1. Log in to your [Product Hunt](https://www.producthunt.com/) account.
|
||||
2. Add a [new application](https://www.producthunt.com/v1/oauth/applications) (E.g. name: Leon; Redirect URI: https://localhost).
|
||||
3. Once your application is created, click `Create Token`.
|
||||
4. Copy the `Developer Token` and paste it in `packages/trend/config/config.json` at the `producthunt.developer_token` key.
|
||||
|
||||
```
|
||||
(en-US) "What's trending on Product Hunt?"
|
||||
(en-US) "Give me the 4 GitHub trends of this week for the JavaScript language"
|
||||
(en-US) "What's the three GitHub trends of this month?"
|
||||
(fr-FR) "Quelles sont les tendances sur GitHub ?"
|
||||
(fr-FR) "Donne-moi les 4 tendances GitHub de cette semaine pour le langage JavaScript"
|
||||
(fr-FR) "Donne-moi les trois tendances GitHub de ce mois"
|
||||
...
|
||||
```
|
||||
|
@ -3,6 +3,7 @@
|
||||
"options": {}
|
||||
},
|
||||
"producthunt": {
|
||||
"developer_token": "YOUR_DEVELOPER_TOKEN",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,22 @@
|
||||
"Let me reach GitHub..."
|
||||
],
|
||||
"today": [
|
||||
"Here are the %limit% latest GitHub trends of today:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the day:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"week": [
|
||||
"Here are the %limit% latest GitHub trends of this week:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the week:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"month": [
|
||||
"Here are the %limit% latest GitHub trends of this month:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the month:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"today_with_tech": [
|
||||
"Here are the %limit% latest GitHub trends of today for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the day for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"week_with_tech": [
|
||||
"Here are the %limit% latest GitHub trends of this week for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the week for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"month_with_tech": [
|
||||
"Here are the %limit% latest GitHub trends of this month for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
"Here are the %limit% GitHub trends of the month for the %tech% technology:<br><br><ul>%result%</ul>"
|
||||
],
|
||||
"unreachable": [
|
||||
"GitHub is unreachable for the moment, please retry later.",
|
||||
@ -36,5 +36,24 @@
|
||||
]
|
||||
},
|
||||
"producthunt": {
|
||||
"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>"
|
||||
],
|
||||
"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>"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -36,5 +36,24 @@
|
||||
]
|
||||
},
|
||||
"producthunt": {
|
||||
"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, veuille patienter une seconde...",
|
||||
"Laissez moi atteindre Product Hunt..."
|
||||
],
|
||||
"today": [
|
||||
"Voici les %limit% dernières tendances Product Hunt du jour :<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>"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,60 @@ import requests
|
||||
import utils
|
||||
|
||||
def producthunt(string, entities):
|
||||
"""WIP..."""
|
||||
"""Grab the Product Hunt trends"""
|
||||
|
||||
return utils.output('end', 'done')
|
||||
# Developer token
|
||||
developertoken = utils.config('developer_token')
|
||||
|
||||
# Number of products
|
||||
limit = 5
|
||||
|
||||
# Answer key
|
||||
answerkey = 'today'
|
||||
|
||||
for item in entities:
|
||||
if item['entity'] == 'number':
|
||||
limit = item['resolution']['value']
|
||||
|
||||
utils.output('inter', 'reaching', utils.translate('reaching'))
|
||||
|
||||
try:
|
||||
r = utils.http('GET', 'https://api.producthunt.com/v1/posts', { 'Authorization': 'Bearer ' + developertoken })
|
||||
posts = list(enumerate(r.json()['posts']))
|
||||
result = ''
|
||||
|
||||
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:
|
||||
author = { 'profile_url': '?', 'name': '?' }
|
||||
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']
|
||||
}
|
||||
)
|
||||
|
||||
if (i + 1) == limit:
|
||||
break
|
||||
|
||||
return utils.output('end', answerkey, utils.translate(answerkey, {
|
||||
'limit': limit,
|
||||
'result': result
|
||||
}
|
||||
)
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
return utils.output('end', 'unreachable', utils.translate('unreachable'))
|
||||
|
@ -1,31 +1,15 @@
|
||||
{
|
||||
"lang": "en",
|
||||
"package": "checker",
|
||||
"module": "isitdown",
|
||||
"query": "Check if github.com, mozilla.org and twitter.com are up",
|
||||
"package": "trend",
|
||||
"module": "producthunt",
|
||||
"query": "What's the 50 latest trends on Product Hunt?",
|
||||
"entities": [
|
||||
{
|
||||
"sourceText": "github.com",
|
||||
"utteranceText": "github.com",
|
||||
"entity": "url",
|
||||
"entity": "number",
|
||||
"resolution": {
|
||||
"value": "github.com"
|
||||
}
|
||||
},
|
||||
{
|
||||
"sourceText": "mozilla.org",
|
||||
"utteranceText": "mozilla.org",
|
||||
"entity": "url",
|
||||
"resolution": {
|
||||
"value": "mozilla.org"
|
||||
}
|
||||
},
|
||||
{
|
||||
"sourceText": "twitter.com",
|
||||
"utteranceText": "twitter.com",
|
||||
"entity": "url",
|
||||
"resolution": {
|
||||
"value": "twitter.com"
|
||||
"strValue": "50",
|
||||
"value": 50,
|
||||
"subtype": "integer"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user