Skip to content

grinrill/tgquote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tgquote

Python module for screenshoting telegram messages.

Installation

pip install git+https://github.com/grinrill/tgquote

Example

from tgquote import TelegramImageRenderer
from tgquote.renderers import HtmlCssToImageRenderer
from tgquote.filegetters import DefaultFileGetter


from aiogram import Bot, Dispatcher, executor, types
bot = Bot('your bot token')
dp = Dispatcher(bot)

quoter = TelegramImageRenderer(
  HtmlCssToImageRenderer(
    api_id = 'your htmlcsstoimage.com api_id',
    api_key = 'your htmlcsstoimage.com api_key',
    api_url='https://htmlcsstoimage.com/demo_run'
    # I use demo apis for tests
    # I DO NOT RECOMMEND using the demo api in the prod
    
    # also instead of htmlcsstoimage.com you can use pyppeteer for local rendering
    # see below in the readme
  ),
  DefaultFileGetter(bot),
  append_css='body {background-color: grey}',
  # by default background is transparent
)


@dp.message_handler(
  content_types=types.ContentTypes.ANY
)
async def handler(message):
  await message.chat.do('upload_photo')
  f = await quoter.render(message)
  await message.reply_photo(f)
  
executor.start_polling(dp, skip_updates=True)

Render engines

Render engine object should be provided as the first argument in TelegramImageRenderer. Currently two renderers available: HtmlCssToImageRenderer using htmlcsstoimage.com api and PyppeteerRenderer using pyppeteer.

HtmlCssToImageRenderer

You need api_id and api_key to use this api, you can get it here: https://htmlcsstoimage.com/dashboard/api-keys.

render_engine = HtmlCssToImageRenderer(
  api_id = 'your htmlcsstoimage.com api_id',
  api_key = 'your htmlcsstoimage.com api_key'
)

PyppeteerRenderer

You need to install pyppeteer: https://github.com/miyakogi/pyppeteer#installation.

render_engine = PyppeteerRenderer()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published