commit
7422250c21
|
@ -0,0 +1,43 @@
|
||||||
|
# This workflows will upload a Python Package using Twine when a release is created
|
||||||
|
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
|
||||||
|
|
||||||
|
name: Upload Python Package
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v3
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install setuptools wheel twine
|
||||||
|
- name: Install pibooth
|
||||||
|
run: |
|
||||||
|
sudo apt-get install libsdl* libsmpeg-dev libportmidi-dev
|
||||||
|
pip install pibooth
|
||||||
|
- name: Install telegram client
|
||||||
|
run: |
|
||||||
|
pip install python-telegram-bot
|
||||||
|
- name: Build and publish
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
||||||
|
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
python setup.py sdist bdist_wheel
|
||||||
|
twine check dist/* && twine upload --skip-existing dist/*
|
|
@ -0,0 +1,29 @@
|
||||||
|
/tmp
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
pip-wheel-metadata/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
.vscode/
|
|
@ -0,0 +1,36 @@
|
||||||
|
pibooth-telegram-upload
|
||||||
|
=================
|
||||||
|
|
||||||
|
[![Python 3.6+](https://img.shields.io/badge/python-3.6+-red.svg)](https://www.python.org/downloads)
|
||||||
|
[![PyPi package](https://badge.fury.io/py/pibooth-telegram-upload.svg)](https://pypi.org/project/pibooth-telegram-upload)
|
||||||
|
[![PyPi downloads](https://img.shields.io/pypi/dm/pibooth-telegram-upload?color=purple)](https://pypi.org/project/pibooth-telegram-upload)
|
||||||
|
|
||||||
|
`pibooth-telegram-upload` is a plugin for the [pibooth](https://pypi.org/project/pibooth) application.
|
||||||
|
|
||||||
|
Install
|
||||||
|
-------
|
||||||
|
|
||||||
|
$ pip3 install pibooth-telegram-upload
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Below are the new configuration options available in the [pibooth](https://pypi.org/project/pibooth) configuration. **The keys and their default values are automatically added to your configuration after first** [pibooth](https://pypi.org/project/pibooth) **restart.**
|
||||||
|
|
||||||
|
``` {.ini}
|
||||||
|
[Telegram]
|
||||||
|
|
||||||
|
# Telegram bot token
|
||||||
|
telegram_token =
|
||||||
|
|
||||||
|
# Chat/Channel id
|
||||||
|
telegram_chat_id =
|
||||||
|
|
||||||
|
# Message to show when sending the picture
|
||||||
|
telegram_message =
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Note
|
||||||
|
|
||||||
|
Edit the configuration by running the command `pibooth --config`.
|
|
@ -0,0 +1,75 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""pibooth plugin for uploading pictures to Telegram"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import telegram
|
||||||
|
|
||||||
|
try:
|
||||||
|
from telegram.error import TelegramError
|
||||||
|
except ImportError:
|
||||||
|
InstalledAppFlow = None
|
||||||
|
pass
|
||||||
|
|
||||||
|
import pibooth
|
||||||
|
from pibooth.utils import LOGGER
|
||||||
|
|
||||||
|
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
|
||||||
|
SECTION = "Telegram"
|
||||||
|
|
||||||
|
|
||||||
|
@pibooth.hookimpl
|
||||||
|
def pibooth_configure(cfg):
|
||||||
|
"""Declare the new configuration options"""
|
||||||
|
cfg.add_option(SECTION, "telegram_token", "", "Telegram Token")
|
||||||
|
cfg.add_option(SECTION, "telegram_chat_id", "", "Telegram chat ID")
|
||||||
|
cfg.add_option(
|
||||||
|
SECTION,
|
||||||
|
"telegram_message",
|
||||||
|
"",
|
||||||
|
"Message sended on every posted photo",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pibooth.hookimpl
|
||||||
|
def pibooth_startup(app, cfg):
|
||||||
|
"""Verify Telegram credentials"""
|
||||||
|
telegram_token = cfg.get(SECTION, "telegram_token")
|
||||||
|
telegram_chat_id = cfg.get(SECTION, "telegram_chat_id")
|
||||||
|
|
||||||
|
if not telegram_token:
|
||||||
|
LOGGER.error(
|
||||||
|
"Telegram Token not defined in ["
|
||||||
|
+ SECTION
|
||||||
|
+ "][telegram_token], uploading deactivated"
|
||||||
|
)
|
||||||
|
elif not telegram_chat_id:
|
||||||
|
LOGGER.error(
|
||||||
|
"Telegram Chat ID not defined in ["
|
||||||
|
+ SECTION
|
||||||
|
+ "][telegram_chat_id], uploading deactivated"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
LOGGER.info("Initializing Telegram client")
|
||||||
|
app.telegram_client = telegram.Bot(token=telegram_token)
|
||||||
|
|
||||||
|
|
||||||
|
@pibooth.hookimpl
|
||||||
|
def state_processing_exit(app, cfg):
|
||||||
|
"""Upload picture to Telegram chat"""
|
||||||
|
if hasattr(app, "telegram_client"):
|
||||||
|
chat_id = cfg.get(SECTION, "telegram_chat_id").strip('"')
|
||||||
|
upload_path = os.path.basename(app.previous_picture_file)
|
||||||
|
message = cfg.get(SECTION, "telegram_message")
|
||||||
|
try:
|
||||||
|
response = app.telegram_client.send_photo(
|
||||||
|
chat_id=chat_id,
|
||||||
|
caption=message,
|
||||||
|
photo=app.previous_picture_file,
|
||||||
|
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||||
|
)
|
||||||
|
LOGGER.info("File uploaded to Telegram chat: " + response)
|
||||||
|
except TelegramError as e:
|
||||||
|
LOGGER.error(e)
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from io import open
|
||||||
|
import os.path as osp
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
HERE = osp.abspath(osp.dirname(__file__))
|
||||||
|
sys.path.insert(0, HERE)
|
||||||
|
import pibooth_telegram_upload as plugin # nopep8 : import shall be done after adding setup to paths
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
setup(
|
||||||
|
name=plugin.__name__,
|
||||||
|
version=plugin.__version__,
|
||||||
|
description=plugin.__doc__,
|
||||||
|
long_description=open(osp.join(HERE, "README.md"), encoding="utf-8").read(),
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
classifiers=[
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"Environment :: Other Environment",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Intended Audience :: End Users/Desktop",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
||||||
|
"Operating System :: POSIX :: Linux",
|
||||||
|
"Programming Language :: Python :: 3.6",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Natural Language :: English",
|
||||||
|
"Topic :: Multimedia :: Graphics :: Capture :: Digital Camera",
|
||||||
|
],
|
||||||
|
author="Dídac Sabatés",
|
||||||
|
author_email="sabatesduran@gmail.com",
|
||||||
|
url="https://github.com/sabatesduran/pibooth-telegram-upload",
|
||||||
|
download_url="https://github.com/sabatesduran/pibooth-telegram-upload/archive/{}.tar.gz".format(
|
||||||
|
plugin.__version__
|
||||||
|
),
|
||||||
|
license="GPLv3",
|
||||||
|
platforms=["unix", "linux"],
|
||||||
|
keywords=["Raspberry Pi", "camera", "photobooth", "telegram", "chat", "bot", "channel"],
|
||||||
|
py_modules=["pibooth_telegram_upload"],
|
||||||
|
python_requires=">=3.6",
|
||||||
|
install_requires=["pibooth>=2.0.0", "python-telegram-bot==13.12"],
|
||||||
|
zip_safe=False, # Don't install the lib as an .egg zipfile
|
||||||
|
entry_points={"pibooth": ["pibooth_telegram_upload = pibooth_telegram_upload"]},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue