From 820e07863e6c069bb366c242eedec81740a603a6 Mon Sep 17 00:00:00 2001 From: Robb Date: Tue, 9 May 2023 23:18:56 -0600 Subject: [PATCH] Initial commit --- .gitignore | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ campcam.py | 39 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 .gitignore create mode 100644 campcam.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3dd6f08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,117 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Editor +*.swp +*.swo + +# DB +db.sqlite3 + +# nodejs +node_modules/ + +# tbot specific: +settings.py +*.session +*.session-journal +secrets.py + +data/ diff --git a/campcam.py b/campcam.py new file mode 100644 index 0000000..87a5f06 --- /dev/null +++ b/campcam.py @@ -0,0 +1,39 @@ +import telegram +from telegram.ext import CommandHandler, Updater +import picamera +import time +import os +import secrets + +bot = telegram.Bot(token=secrets.API_TOKEN) + +def send_photo(update, context): + # Take a photo with the Raspberry Pi camera + + print('Got campcam command') + + with picamera.PiCamera() as camera: + camera.resolution = (2592, 1944) + camera.start_preview() + # Camera warm-up time + time.sleep(5) + # Save the photo to a file + filename = 'data/' + str(int(time.time())) + '.jpg' + camera.capture(filename) + + print('Saved file to', filename) + + chat_id = update.message.chat_id + message_id = update.message.message_id + bot.send_photo(chat_id=chat_id, photo=open(filename, 'rb'), reply_to_message_id=message_id) + + print('Sent to chat') + +send_photo_handler = CommandHandler('campcam', send_photo) +updater = Updater(bot=bot, workers=1) +dispatcher = updater.dispatcher +dispatcher.add_handler(send_photo_handler) + +print('Loaded.') + +updater.start_polling()