-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg_publish.py
36 lines (29 loc) · 1017 Bytes
/
arg_publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import random
import telegram
import argparse
from pathlib import PurePath
from dotenv import load_dotenv
from publish_image import publish_image
def arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument("image_path", nargs="?")
args = parser.parse_args()
return args
def publish_arg(telegram_token, chat_id):
bot = telegram.Bot(token=telegram_token)
image_path = arg_parser().image_path
if image_path:
image_path = PurePath('images', image_path)
publish_image(image_path, chat_id, bot)
else:
dir_images = os.walk('images')
for i, j, images in dir_images:
random_image = random.choice(images)
image_path = PurePath('images', random_image)
publish_image(image_path, chat_id, bot)
if __name__ == "__main__":
load_dotenv()
telegram_token = os.environ['TELEGRAM_TOKEN']
chat_id = os.environ['CHAT_ID']
publish_arg(telegram_token, chat_id)