Im trying to make this script run on telegram which works fine until i send a picture to the bot and it gives me this error.
I am trying to run this script:
import os
import subprocess
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
# Replace 'TOKEN' with your actual Telegram bot token
TOKEN = 'XXXXXXXXXXXXXXX'
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Send me a picture and I will change its metadata!')
def handle_photo(update: Update, context: CallbackContext) -> None:
# Get photo file ID
photo = update.message.photo[-1]
photo_file = context.bot.get_file(photo.file_id)
# Download photo
photo_file.download('temp.jpg')
# Change metadata
metadata_changes = {'Title': 'New Title', 'Description': 'New Description'}
change_metadata('temp.jpg', metadata_changes)
# Send the modified photo back
update.message.reply_photo(open('temp.jpg', 'rb'))
def change_metadata(image_path, metadata_changes):
"""
Change metadata of an image file.
Args:
- image_path (str): Path to the image file.
- metadata_changes (dict): Dictionary containing metadata changes.
Example: {'Title': 'New Title', 'Description': 'New Description'}
"""
# Build the command to change metadata using exiftool
command = ['exiftool']
for key, value in metadata_changes.items():
command.extend(['-'+key+'='+value])
command.append(image_path)
# Execute the command
try:
subprocess.run(command, check=True)
print("Metadata changed successfully.")
except subprocess.CalledProcessError as e:
print("Error:", e)
def main() -> None:
updater = Updater(TOKEN)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(MessageHandler(Filters.photo & ~Filters.command, handle_photo))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
but when i try to run PS C:UsersUsertelegram-bot> python telegram_metadata_bot.py i keep getting this error (after a dozen lines of code processes):
FileNotFoundError: [WinError 2] The system cannot find the file specified
“temp.jpg” is inside the “telegram-bot” folder and so is the exiftool executable file and the extra files i extracted.
i have Python 3.12.3 installed and im running this script on terminal with adminstrator permission.
how do i solve this issue? im new to running scripts and coding so i apologize if this is a dumb question.
i tried googling this issue but none helped me
user24769617 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.