Skip to content

Instantly share code, notes, and snippets.

@cthoyt
Created July 19, 2021 20:09
Show Gist options
  • Save cthoyt/05e3eb573789f646bcc8e28e0d48aa50 to your computer and use it in GitHub Desktop.
Save cthoyt/05e3eb573789f646bcc8e28e0d48aa50 to your computer and use it in GitHub Desktop.
PyKEEN tweet generator
"""Generate PyKEEN model tweets."""
from textwrap import dedent
import click
from docdata import get_docdata
from pykeen.models import model_resolver
@click.command()
@click.argument('name') # the name of the model
@click.option('--pr', help='The pull request number to include a "Code" link')
@click.option('--force', is_flag=True, help='Output options even if they exceed the tweet character length limit')
def main(name: str, pr=None, force: bool = False):
"""Generate PyKEEN new model tweets!"""
model_cls = model_resolver.lookup(name)
model_docdata = get_docdata(model_cls)
name = model_docdata.get('name', model_cls.__name__)
cite = model_docdata['citation']
s = dedent(f'''\
PyKEEN now implements {name} from {cite['author']} et al ({cite['year']})!
📜 Paper: {cite['link']}
''')
usage = dedent(f'''\
🚀 Usage:
>>> from pykeen.pipeline import pipeline
>>> pipeline(model='{model_cls.__name__}', dataset='FB15k')\n
''')
if force or (len(s) + len(usage) <= 280):
s += usage
docs = f'📖 Docs: https://pykeen.rtfd.io/en/latest/api/pykeen.models.{model_cls.__name__}.html\n\n'
if force or (len(s) + len(docs) <= 280):
s += docs
if pr is not None:
code = f'🖥️ Code: https://github.com/pykeen/pykeen/pull/{pr}\n'
if force or (len(s) + len(code) <= 280):
s += code
print(s)
print(f'Length:', len(s))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment