Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import json
- import urllib.request
- bot = telebot.TeleBot(*ТУТ ТОКЕН*)
- class Getter:
- def processMessage(self, message):
- if message.text.find('/парсить') != 0:
- return 0
- if len(message.text) > len("/парсить") + 2:
- string = ""
- for x in range(len("/парсить") + 1, len(message.text)):
- string += message.text[x]
- request = urllib.request.Request("https://2ch.hk/b/res/" + string + ".json")
- response = urllib.request.urlopen(request)
- processed = json.loads(response.read())
- webms = []
- for post in processed['threads'][0]['posts']:
- if 'files' not in post:
- continue
- for file in post['files']:
- if file['name'].find(".webm") != -1:
- webms.append(file['path'])
- if len(webms) != 0:
- for x in webms:
- request = urllib.request.Request("https://2ch.hk" + x)
- bot.send_video(message.chat.id, urllib.request.urlopen(request).read())
- return 1
- class PlaceHolder():
- def processMessage(self, message):
- return 0
- handlers = (Getter(), PlaceHolder())
- def handleMessages(messages):
- for message in messages:
- if message.content_type == 'text':
- for handler in handlers:
- if handler.processMessage(message) == 1:
- break
- bot.set_update_listener(handleMessages)
- bot.polling()
Advertisement
Add Comment
Please, Sign In to add comment