전보다 더 큰 프로젝트의 일환으로 봇을 쓰고 있습니다. 그러나 이미지를 다운로드 할 때마다 봇에게 새 파일을 쓰는 것 같지 않습니다. 대신 첫 번째 이미지를 덮어 씁니다. 받았다.전보 사진 봇
내가 건너 온 또 다른 문제는 사용자의 입력/사진없이 이미지를 다운로드하는 것입니다, 난 그렇게는 "기능"하지만 이유는 그게 전부 경우에 저
에게 설명하십시오를 호출 할 수 있습니다 마음을하지 않았다 도움
import logging
from telegram.ext import MessageHandler, Filters
from telegram.ext import Updater
import os
import os.path
import datetime
import sys
updater = Updater(token= 'omitted')
from telegram.ext import Updater, CommandHandler
time = datetime.datetime.now().strftime("%d-%m-%y_%H:%M,%S")
def start(bot, update):
update.message.reply_text('Hello World!')
def hello(bot, update):
update.message.reply_text(
'Hello {}'.format(update.message.from_user.first_name))
def photo(bot, update):
save_path = '/Users/barthofman/Desktop/grandtest/'
file_id = update.message.photo[-1].file_id
newFile = bot.getFile(file_id)
newFile.download(os.path.join(save_path, time+'.jpg'))
bot.sendMessage(chat_id=update.message.chat_id, text="download succesful")
filename = (time+'jpg')
with open(filename,"rb") as f:
Jpegcontents = (f.read())
if Jpegcontents.startswith(b"\xff\xd8") and Jpegcontents.endswith(b"\xff\xd9"):
bot.sendMessage(chat_id=update.message.chat_id, text="Valid Image")
if not Jpegcontents.startswith(b"\xff\xd8") and Jpegcontents.endswith(b"\xff\xd9"):
os.system("rm ",filename)
photo_handler = MessageHandler(Filters.photo, photo)
updater.dispatcher.add_handler(photo_handler)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('hello', hello))
updater.start_polling()
updater.idle()
updater.stop()
새 인증 토큰을 생성하는 것이 좋습니다. 그들은 비공개로 유지해야합니다. – Caramiriel
def 사진 안에 시간 변수를 설정하면 안됩니까? – redFIVE
... 당신이 맞다, 완전히 놓친 – BluePython