Browse Source

Prettier printing

main
Unbewohnte 3 years ago
parent
commit
a8e100971a
  1. 44
      vkImageSender/VkImageSender.py

44
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

Loading…
Cancel
Save