Answer the question
In order to leave comments, you need to log in
How to execute another piece of python code?
python 3.8
code
import telebot
import requests
#качаем нужный файл
def download(fileName):
f = open(fileName,'wb')
f.write(requests.get('site.com', headers={'User-Agent': 'My User Agent 1.0'}).content)
f.close()
for i in range(1):
download(str(i)+'.jpg')
#отправляем скачаный файл пользователю при нажатии start
bot = telebot.TeleBot('token')
@bot.message_handler(commands=['start'])
def start_message(message):
chat_id=id
bot.send_photo(chat_id=chat_id, photo=open('0.jpg', 'rb'))
bot.polling()
#качаем нужный файл
def download(fileName):
f = open(fileName,'wb')
f.write(requests.get('site.com', headers={'User-Agent': 'My User Agent 1.0'}).content)
f.close()
for i in range(1):
download(str(i)+'.jpg')
Answer the question
In order to leave comments, you need to log in
The solution was suggested by the user in the comments Andrey call the download function in the start_message function
def download(fileName):
f = open(fileName,'wb')
f.write(requests.get('site.com', headers={'User-Agent': 'My User Agent 1.0'}).content)
f.close()
while True
download(str(i)+'.jpg')
def download(fileName):
f = open(fileName,'wb')
f.write(requests.get('site.com', headers={'User-Agent': 'My User Agent 1.0'}).content)
f.close()
for i in range(100):
download(str(i)+'.jpg')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question