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 vk_api import VkUpload
from time import sleep from time import sleep
def has_image_extention(filename): def has_image_extention(filename):
filename = filename.lower() filename = filename.lower()
image_extentions = ["jpg","png","bmp","jpeg"] image_extentions = ["jpg","png","bmp","jpeg"]
for image_extention in image_extentions: for image_extention in image_extentions:
if image_extention in filename: if image_extention in filename:
return True return True
return False return False
def sendImages(img_dir = ".", ID = 0, IS_GROUP_CHAT = False, TOKEN = ""): 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 via API
upload = VkUpload(vk) upload = VkUpload(vk)
upload_img = upload.photo_messages(photos = path_to_image)[0] upload_img = upload.photo_messages(photos = path_to_image)[0]
# each message will contain "Counter : {number_of_}" # each message will contain "Counter : {number_of_}"
MESSAGE = "Counter : {}".format(counter) MESSAGE = "Counter : ┃{}┃ The next appr. at ~ ┃{}".format(counter,
datetime.datetime.now() + datetime.timedelta(seconds=4))
# sending # sending
print("{}: Sending {}...".format(counter,filename)) print("{}: Sending {}...".format(counter,filename))
if IS_GROUP_CHAT == False: if IS_GROUP_CHAT == False:
vk.messages.send(user_id = ID ,message=MESSAGE, try:
attachment = 'photo{}_{}'.format(upload_img['owner_id'],upload_img['id']), vk.messages.send(user_id = ID ,message=MESSAGE,
random_id = 0) attachment = 'photo{}_{}'.format(upload_img['owner_id'],upload_img['id']),
elif IS_GROUP_CHAT == True:
vk.messages.send(chat_id = ID, message=MESSAGE,
attachment='photo{}_{}'.format(upload_img['owner_id'],upload_img['id']),
random_id = 0) 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 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)) sleep(random.uniform(3.0,4.0))
pass pass
@ -55,7 +65,7 @@ if __name__ == '__main__':
images = '' images = ''
token = '' token = ''
id = 0 id = 0
sendImages(img_dir = images, ID = id, IS_GROUP_CHAT = False, TOKEN = token) sendImages(img_dir = images, ID = id, IS_GROUP_CHAT = False, TOKEN = token)
pass pass

Loading…
Cancel
Save