Answer the question
In order to leave comments, you need to log in
What needs to be changed in the code so that it starts automatic mailing at the specified time, and while the bot is running, I can add new photos to the folder?
There is a script, it is necessary for it to send a photo with the same text for all photos, and so that I can add a new photo to the folder while the bot is running, since while it is running, I cannot add new photos (the bot will not send them), tell me what needs to be changed in the code?
# Переменные для итерации фото
mypath = "images"
photos = set()
# formats = ['.jpg', '.jpeg', '.png']
# savedSet = set()
# Переменные для ссылки на канал
one = 'Name channel'
two = 'link on channel'
three = '@linkonchannel'
url = two
# Переменные для итерации времени
time = ('10:17', '04:20', '04:22')
async def send_post():
while True:
now_global = datetime.datetime.now()
now_global = str(now_global.time())
now_global = now_global.split('.')[0]
now_global = now_global[:-3]
if now_global in time:
async def process_images(path: str, old_images: set):
images = os.listdir(path)
images = set(images)
# Список фото
print(images)
images = images - old_images
print(old_images)
for i in images:
now_local = datetime.datetime.now()
now_local = str(now_local.time())
now_local = now_local.split('.')[0]
now_local = now_local[:-3]
if now_local in time:
await bot.send_photo(chat_id=channels, photo=photos, caption=f'{hlink(one, url=two)}\n'
f'{hlink(two, url=two)}\n'
f'{hlink(three, url=two)}')
else:
print('Ожидаю 12:00')
# await asyncio.sleep(64800)
print(i)
# await asyncio.sleep(10800)
async def a(param1, param2=None):
if param2 is None:
param2 = {}
await a(process_images(path=mypath, old_images=photos))
else:
print('Ожидаю 12:00')
# await asyncio.sleep(64800)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question