From a8e100971a7ec1870725b20b597f90ac5ef11232 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Mon, 21 Jun 2021 17:18:59 +0300 Subject: [PATCH] Prettier printing --- vkImageSender/VkImageSender.py | 44 +++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/vkImageSender/VkImageSender.py b/vkImageSender/VkImageSender.py index 707b450..4b74c6d 100644 --- a/vkImageSender/VkImageSender.py +++ b/vkImageSender/VkImageSender.py @@ -1,16 +1,16 @@ -import vk_api,os,random +import vk_api,os,random, datetime from vk_api import VkUpload from time import sleep def has_image_extention(filename): filename = filename.lower() - + image_extentions = ["jpg","png","bmp","jpeg"] for image_extention in image_extentions: if image_extention in filename: return True - + return False def sendImages(img_dir = ".", ID = 0, IS_GROUP_CHAT = False, TOKEN = ""): @@ -30,23 +30,33 @@ def sendImages(img_dir = ".", ID = 0, IS_GROUP_CHAT = False, TOKEN = ""): # upload via API upload = VkUpload(vk) upload_img = upload.photo_messages(photos = path_to_image)[0] - - # each message will contain "Counter : {number_of_}" - MESSAGE = "Counter : {}".format(counter) + + # each message will contain "Counter : {number_of_}" + MESSAGE = "Counter : ┃{}┃ The next appr. at ~ ┃{}┃".format(counter, + datetime.datetime.now() + datetime.timedelta(seconds=4)) # sending - print("{}: Sending {}...".format(counter,filename)) + print("• {}: Sending {}...".format(counter,filename)) if IS_GROUP_CHAT == False: - vk.messages.send(user_id = ID ,message=MESSAGE, - attachment = 'photo{}_{}'.format(upload_img['owner_id'],upload_img['id']), - random_id = 0) - elif IS_GROUP_CHAT == True: - vk.messages.send(chat_id = ID, message=MESSAGE, - attachment='photo{}_{}'.format(upload_img['owner_id'],upload_img['id']), + try: + vk.messages.send(user_id = ID ,message=MESSAGE, + attachment = 'photo{}_{}'.format(upload_img['owner_id'],upload_img['id']), random_id = 0) + except Exception as e: + print(e) + break + elif IS_GROUP_CHAT == True: + try: + vk.messages.send(chat_id = ID, message=MESSAGE, + attachment='photo{}_{}'.format(upload_img['owner_id'],upload_img['id']), + random_id = 0) + except Exception as e: + print(e) + break + counter += 1 - - # giving a bit of a rest to VK + + # giving a bit of a rest to VK sleep(random.uniform(3.0,4.0)) pass @@ -55,7 +65,7 @@ if __name__ == '__main__': images = '' token = '' id = 0 - + sendImages(img_dir = images, ID = id, IS_GROUP_CHAT = False, TOKEN = token) - + pass