Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import random
- import time
- import telepot
- from telepot.loop import MessageLoop
- chemin = "/ton/chemin/ici"
- channelid = 000 #remplace 000 par l'id du channel
- token = "ton token ici"
- def getListOfFiles(dirName):
- # create a list of file and sub directories
- # names in the given directory
- listOfFile = os.listdir(dirName)
- allFiles = list()
- # Iterate over all the entries
- for entry in listOfFile:
- # Create full path
- fullPath = os.path.join(dirName, entry)
- # If entry is a directory then get the list of files in this directory
- if os.path.isdir(fullPath):
- allFiles = allFiles + getListOfFiles(fullPath)
- else:
- allFiles.append(fullPath)
- return allFiles
- def getrandom():
- randomfile = random.choice(getListOfFiles(chemin))
- if randomfile.endswith('.gif'):
- getrandom()
- else:
- return randomfile
- def handle(msg):
- # content_type, chat_type, chat_id = telepot.glance(msg)
- # print(content_type, chat_type, chat_id)
- randomfile = getrandom()
- bot.sendPhoto(channelid, open(randomfile, 'rb'))
- time.sleep(5)
- exit()
- def main():
- global bot
- bot = telepot.Bot(token)
- handle("")
- while 1:
- time.sleep(3)
- main()
Advertisement
Add Comment
Please, Sign In to add comment