-
Notifications
You must be signed in to change notification settings - Fork 1
/
telegram_photo_uploader.py
executable file
·52 lines (44 loc) · 1.24 KB
/
telegram_photo_uploader.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import telegram
import os
import sys
import getopt
import asyncio
async def main():
tg_token = ''
tg_chat_id = ''
owner_id = ''
argv = sys.argv[1:]
try:
opts, args = getopt.getopt(argv, "t:o:c:")
except:
print("Error")
for opt, arg in opts:
if opt in ["-t"]:
tg_token = arg
elif opt in ["-o"]:
owner_id = arg
elif opt in ["-c"]:
tg_chat_id = arg
image_dir = str(owner_id).lstrip('-')
file_name = str(image_dir) + '_last.txt'
last = open(file_name, 'a+')
count=0
for filename in os.listdir(image_dir):
f = os.path.join(image_dir, filename)
if os.path.isfile(f):
if f in open(file_name).read():
print('file exits in last')
else:
bot = telegram.Bot(token=tg_token)
last.write(f + '\n')
await bot.sendPhoto(chat_id=tg_chat_id, photo=open(f, 'rb'))
count = count + 1
if count == 1:
print('count limit reached')
break
last.close()
if __name__ == '__main__':
asyncio.run(main())