parent
095fc5f2b4
commit
727a30402c
@ -1,4 +1,4 @@
|
|||||||
# Telegram_Image-Watchdog
|
# Telegram_Image-Watchdog
|
||||||
|
|
||||||
Watches a directory for a new image.
|
Watches a directory for a new image.
|
||||||
When is finds a new image it sends it to the group.
|
When it finds a new image it sends it to the group.
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import telebot
|
||||||
|
|
||||||
|
botToken = "5698919505:AAFQEQEzxxw7elxQItir4ofTF4KulCmDTLE"
|
||||||
|
bot = telebot.TeleBot(botToken)
|
||||||
|
chatId = "-752937487"
|
||||||
|
|
||||||
|
import time
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
from watchdog.events import PatternMatchingEventHandler
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
patterns = ["*"]
|
||||||
|
ignore_patterns = None
|
||||||
|
ignore_directories = True
|
||||||
|
case_sensitive = False
|
||||||
|
my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)
|
||||||
|
|
||||||
|
def on_created(event):
|
||||||
|
bot.send_photo(chat_id=chatId, photo=open(event.src_path, 'rb'))
|
||||||
|
|
||||||
|
my_event_handler.on_created = on_created
|
||||||
|
|
||||||
|
path = "."
|
||||||
|
go_recursively = False
|
||||||
|
my_observer = Observer()
|
||||||
|
my_observer.schedule(my_event_handler, path, recursive=go_recursively)
|
||||||
|
|
||||||
|
|
||||||
|
my_observer.start()
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
my_observer.stop()
|
||||||
|
my_observer.join()
|
Reference in new issue