1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-27 08:06:03 +03:00

refactor(skill/github_trend): from module to skill

This commit is contained in:
louistiti 2022-02-22 08:44:21 +08:00
parent 6f04e36342
commit 4029759ba7
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
11 changed files with 742 additions and 1 deletions

View File

@ -40,6 +40,15 @@
"route": "/api/action/leon/who_am_i/run",
"params": []
},
{
"method": "POST",
"route": "/api/action/news/github_trends/run",
"params": [
"number",
"daterange"
],
"entitiesType": "builtIn"
},
{
"method": "POST",
"route": "/api/action/productivity/todo_list/create_list",
@ -124,4 +133,4 @@
"params": []
}
]
}
}

View File

View File

@ -0,0 +1,66 @@
{
"actions": {
"run": {
"utterance_samples": [
"What are the trends on GitHub?",
"Give me the GitHub trends",
"What's trending on GitHub?",
"What are the trends on GH?",
"Give me the GH trends",
"What's trending on GH?"
],
"http_api": {
"entities": [
{
"entity": "number",
"resolution": [
"value"
]
},
{
"entity": "daterange",
"resolution": [
"timex"
]
}
]
}
}
},
"answers": {
"limit_max": [
"You've asked for too many GitHub trends, I'll give you 25 trends instead.",
"%limit% GitHub trends is a lot, let me tell you the 25 trends instead."
],
"reaching": [
"I'm reaching GitHub, please wait a second...",
"Let me reach GitHub..."
],
"today": [
"Here are the %limit% GitHub trends of the day:<br><br><ul>%result%</ul>"
],
"week": [
"Here are the %limit% GitHub trends of the week:<br><br><ul>%result%</ul>"
],
"month": [
"Here are the %limit% GitHub trends of the month:<br><br><ul>%result%</ul>"
],
"today_with_tech": [
"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% GitHub trends of the week for the %tech% technology:<br><br><ul>%result%</ul>"
],
"month_with_tech": [
"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.",
"I'm having difficulties to reach GitHub, please retry later.",
"GitHub seems to be down, please try again later."
],
"list_element": [
"<li>#%rank%. <a href=\"%repository_url%\" target=\"_blank\">%repository_name%</a> created by <a href=\"%author_url%\" target=\"_blank\">%author_username%</a> with %stars_nb% new stars.</li>"
]
}
}

View File

@ -0,0 +1,50 @@
{
"actions": {
"run": {
"utterance_samples": [
"Quelles sont les tendances sur GitHub ?",
"Donne-moi les tendances GitHub",
"Qu'est-ce qu'il y a en tendance sur GitHub ?",
"Quelles sont les tendances sur GH ?",
"Donne-moi les tendances GH",
"Qu'est-ce qu'il y a en tendance sur GH ?"
]
}
},
"answers": {
"limit_max": [
"Vous demandez beaucoup trop de tendances, laissez moi plutôt vous donner les 25 tendances.",
"%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...",
"Laissez moi atteindre GitHub..."
],
"today": [
"Voici les %limit% dernières tendances GitHub du jour :<br><br><ul>%result%</ul>"
],
"week": [
"Voici les %limit% dernières tendances GitHub de la semaine :<br><br><ul>%result%</ul>"
],
"month": [
"Voici les %limit% dernières tendances GitHub du mois :<br><br><ul>%result%</ul>"
],
"today_with_tech": [
"Voici les %limit% dernières tendances GitHub du jour pour la technologie %tech% :<br><br><ul>%result%</ul>"
],
"week_with_tech": [
"Voici les %limit% dernières tendances GitHub de la semaine pour la technologie %tech% :<br><br><ul>%result%</ul>"
],
"month_with_tech": [
"Voici les %limit% dernières tendances GitHub du mois pour la technologie %tech% :<br><br><ul>%result%</ul>"
],
"unreachable": [
"GitHub est inaccessible pour le moment, merci de réessayer plus tard.",
"Je rencontre des difficultés pour atteindre GitHub, merci de réessayer plus tard.",
"GitHub semble ne pas fonctionner correctement, veuillez retenter plus tard."
],
"list_element": [
"<li>#%rank%. <a href=\"%repository_url%\" target=\"_blank\">%repository_name%</a> créé par <a href=\"%author_url%\" target=\"_blank\">%author_username%</a> avec %stars_nb% nouvelles étoiles.</li>"
]
}
}

View File

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

View File

@ -0,0 +1,99 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
import utils
from ..lib import github_lang
from re import search, escape
from bs4 import BeautifulSoup
def run(string, entities):
"""Get the GitHub trends"""
# Number of repositories
limit = 5
# Range string
since = 'daily'
# Technology slug
tech_slug = ''
# Technology name
tech = ''
# Answer key
answer_key = 'today'
for item in entities:
if item['entity'] == 'number':
limit = item['resolution']['value']
if item['entity'] == 'daterange':
if item['resolution']['timex'].find('W') != -1:
since = 'weekly'
answer_key = 'week'
else:
since = 'monthly'
answer_key = 'month'
# Feed the languages list based on the GitHub languages list
for i, language in enumerate(github_lang.get_all()):
# Find the asked language
if search(r'\b' + escape(language.lower()) + r'\b', string.lower()):
answer_key += '_with_tech'
tech = language
tech_slug = language.lower()
if limit > 25:
utils.output('inter', 'limit_max', utils.translate('limit_max', {
'limit': limit
}))
limit = 25
elif limit == 0:
limit = 5
utils.output('inter', 'reaching', utils.translate('reaching'))
try:
r = utils.http('GET', 'https://github.com/trending/' + tech_slug + '?since=' + since)
soup = BeautifulSoup(r.text, features='html.parser')
elements = soup.select('article.Box-row', limit=limit)
result = ''
for i, element in enumerate(elements):
repository = element.h1.get_text(strip=True).replace(' ', '')
if (element.img != None):
author = element.img.get('alt')[1:]
else:
author = '?'
has_stars = element.select('span.d-inline-block.float-sm-right')
stars = 0
if has_stars:
stars = element.select('span.d-inline-block.float-sm-right')[0].get_text(strip=True).split(' ')[0]
separators = [' ', ',', '.']
# Replace potential separators number
for j, separator in enumerate(separators):
stars = stars.replace(separator, '')
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,
'stars_nb': stars
}
)
return utils.output('end', answer_key, utils.translate(answer_key, {
'limit': limit,
'tech': tech,
'result': result
}
)
)
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))

View File

@ -0,0 +1,6 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1,500 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def get_all():
return [
'1C Enterprise',
'ABAP',
'ABNF',
'ActionScript',
'Ada',
'Adobe Font Metrics',
'Agda',
'AGS Script',
'Alloy',
'Alpine Abuild',
'AMPL',
'AngelScript',
'Ant Build System',
'ANTLR',
'ApacheConf',
'Apex',
'API Blueprint',
'APL',
'Apollo Guidance Computer',
'AppleScript',
'Arc',
'AsciiDoc',
'ASN.1',
'ASP',
'AspectJ',
'Assembly',
'Asymptote',
'ATS',
'Augeas',
'AutoHotkey',
'AutoIt',
'Awk',
'Ballerina',
'Batchfile',
'Befunge',
'Bison',
'BitBake',
'Blade',
'BlitzBasic',
'BlitzMax',
'Bluespec',
'Boo',
'Brainfuck',
'Brightscript',
'Bro',
'C',
'C#',
'C++',
'C-ObjDump',
'C2hs Haskell',
"Cap'n Proto", 'CartoCSS',
'Ceylon',
'Chapel',
'Charity',
'ChucK',
'Cirru',
'Clarion',
'Clean',
'Click',
'CLIPS',
'Clojure',
'Closure Templates',
'Cloud Firestore Security Rules',
'CMake',
'COBOL',
'CoffeeScript',
'ColdFusion',
'ColdFusion CFC',
'COLLADA',
'Common Lisp',
'Common Workflow Language',
'Component Pascal',
'CoNLL-U',
'Cool',
'Coq',
'Cpp-ObjDump',
'Creole',
'Crystal',
'CSON',
'Csound',
'Csound Document',
'Csound Score',
'CSS',
'CSV',
'Cuda',
'CWeb',
'Cycript',
'Cython',
'D',
'D-ObjDump',
'Darcs Patch',
'Dart',
'DataWeave',
'desktop',
'Diff',
'DIGITAL Command Language',
'DM',
'DNS Zone',
'Dockerfile',
'Dogescript',
'DTrace',
'Dylan',
'E',
'Eagle',
'Easybuild',
'EBNF',
'eC',
'Ecere Projects',
'ECL',
'ECLiPSe',
'Edje Data Collection',
'edn',
'Eiffel',
'EJS',
'Elixir',
'Elm',
'Emacs Lisp',
'EmberScript',
'EML',
'EQ',
'Erlang',
'F#',
'F*',
'Factor',
'Fancy',
'Fantom',
'FIGlet Font',
'Filebench WML',
'Filterscript',
'fish',
'FLUX',
'Formatted',
'Forth',
'Fortran',
'FreeMarker',
'Frege',
'G-code',
'Game Maker Language',
'GAMS',
'GAP',
'GCC Machine Description',
'GDB',
'GDScript',
'Genie',
'Genshi',
'Gentoo Ebuild',
'Gentoo Eclass',
'Gerber Image',
'Gettext Catalog',
'Gherkin',
'GLSL',
'Glyph',
'Glyph Bitmap Distribution Format',
'GN',
'Gnuplot',
'Go',
'Golo',
'Gosu',
'Grace',
'Gradle',
'Grammatical Framework',
'Graph Modeling Language',
'GraphQL',
'Graphviz (DOT)',
'Groovy',
'Groovy Server Pages',
'Hack',
'Haml',
'Handlebars',
'HAProxy',
'Harbour',
'Haskell',
'Haxe',
'HCL',
'HiveQL',
'HLSL',
'HTML',
'HTML+Django',
'HTML+ECR',
'HTML+EEX',
'HTML+ERB',
'HTML+PHP',
'HTML+Razor',
'HTTP',
'HXML',
'Hy',
'HyPhy',
'IDL',
'Idris',
'IGOR Pro',
'Inform 7',
'INI',
'Inno Setup',
'Io',
'Ioke',
'IRC log',
'Isabelle',
'Isabelle ROOT',
'J',
'Jasmin',
'Java',
'Java Properties',
'Java Server Pages',
'JavaScript',
'JFlex',
'Jison',
'Jison Lex',
'Jolie',
'JSON',
'JSON with Comments',
'JSON5',
'JSONiq',
'JSONLD',
'Jsonnet',
'JSX',
'Julia',
'Jupyter Notebook',
'KiCad Layout',
'KiCad Legacy Layout',
'KiCad Schematic',
'Kit',
'Kotlin',
'KRL',
'LabVIEW',
'Lasso',
'Latte',
'Lean',
'Less',
'Lex',
'LFE',
'LilyPond',
'Limbo',
'Linker Script',
'Linux Kernel Module',
'Liquid',
'Literate Agda',
'Literate CoffeeScript',
'Literate Haskell',
'LiveScript',
'LLVM',
'Logos',
'Logtalk',
'LOLCODE',
'LookML',
'LoomScript',
'LSL',
'Lua',
'M',
'M4',
'M4Sugar',
'Makefile',
'Mako',
'Markdown',
'Marko',
'Mask',
'Mathematica',
'MATLAB',
'Maven POM',
'Max',
'MAXScript',
'mcfunction',
'MediaWiki',
'Mercury',
'Meson',
'Metal',
'MiniD',
'Mirah',
'Modelica',
'Modula-2',
'Modula-3',
'Module Management System',
'Monkey',
'Moocode',
'MoonScript',
'MQL4',
'MQL5',
'MTML',
'MUF',
'mupad',
'Myghty',
'NCL',
'Nearley',
'Nemerle',
'nesC',
'NetLinx',
'NetLinx+ERB',
'NetLogo',
'NewLisp',
'Nextflow',
'Nginx',
'Nim',
'Ninja',
'Nit',
'Nix',
'NL',
'NSIS',
'Nu',
'NumPy',
'ObjDump',
'Objective-C',
'Objective-C++',
'Objective-J',
'OCaml',
'Omgrofl',
'ooc',
'Opa',
'Opal',
'OpenCL',
'OpenEdge ABL',
'OpenRC runscript',
'OpenSCAD',
'OpenType Feature File',
'Org',
'Ox',
'Oxygene',
'Oz',
'P4',
'Pan',
'Papyrus',
'Parrot',
'Parrot Assembly',
'Parrot Internal Representation',
'Pascal',
'Pawn',
'Pep8',
'Perl',
'Perl 6',
'PHP',
'Pic',
'Pickle',
'PicoLisp',
'PigLatin',
'Pike',
'PLpgSQL',
'PLSQL',
'Pod',
'Pod 6',
'PogoScript',
'Pony',
'PostCSS',
'PostScript',
'POV-Ray SDL',
'PowerBuilder',
'PowerShell',
'Processing',
'Prolog',
'Propeller Spin',
'Protocol Buffer',
'Public Key',
'Pug',
'Puppet',
'Pure Data',
'PureBasic',
'PureScript',
'Python',
'Python console',
'Python traceback',
'q',
'QMake',
'QML',
'Quake',
'R',
'Racket',
'Ragel',
'RAML',
'Rascal',
'Raw token data',
'RDoc',
'REALbasic',
'Reason',
'Rebol',
'Red',
'Redcode',
'Regular Expression',
"Ren'Py", 'RenderScript',
'reStructuredText',
'REXX',
'RHTML',
'Rich Text Format',
'Ring',
'RMarkdown',
'RobotFramework',
'Roff',
'Rouge',
'RPC',
'RPM Spec',
'Ruby',
'RUNOFF',
'Rust',
'Sage',
'SaltStack',
'SAS',
'Sass',
'Scala',
'Scaml',
'Scheme',
'Scilab',
'SCSS',
'sed',
'Self',
'ShaderLab',
'Shell',
'ShellSession',
'Shen',
'Slash',
'Slice',
'Slim',
'Smali',
'Smalltalk',
'Smarty',
'SMT',
'Solidity',
'SourcePawn',
'SPARQL',
'Spline Font Database',
'SQF',
'SQL',
'SQLPL',
'Squirrel',
'SRecode Template',
'Stan',
'Standard ML',
'Stata',
'STON',
'Stylus',
'SubRip Text',
'SugarSS',
'SuperCollider',
'SVG',
'Swift',
'SystemVerilog',
'Tcl',
'Tcsh',
'Tea',
'Terra',
'TeX',
'Text',
'Textile',
'Thrift',
'TI Program',
'TLA',
'TOML',
'Turing',
'Turtle',
'Twig',
'TXL',
'Type Language',
'TypeScript',
'Unified Parallel C',
'Unity3D Asset',
'Unix Assembly',
'Uno',
'UnrealScript',
'UrWeb',
'Vala',
'VCL',
'Verilog',
'VHDL',
'Vim script',
'Visual Basic',
'Volt',
'Vue',
'Wavefront Material',
'Wavefront Object',
'wdl',
'Web Ontology Language',
'WebAssembly',
'WebIDL',
'Windows Registry Entries',
'wisp',
'World of Warcraft Addon Data',
'X BitMap',
'X Font Directory Index',
'X PixMap',
'X10',
'xBase',
'XC',
'XCompose',
'XML',
'Xojo',
'XPages',
'XProc',
'XQuery',
'XS',
'XSLT',
'Xtend',
'Yacc',
'YAML',
'YANG',
'YARA',
'YASnippet',
'Zephir',
'Zig',
'Zimpl'
]

View File