bots: Move contrib_bots to api/bots*.

This will make it convenient to include these bots in Zulip API
releases on pypi.

Fix #5009.
This commit is contained in:
Rohitt Vashishtha 2017-05-30 11:40:19 +05:30 committed by Tim Abbott
parent 7531c4fb26
commit 894adb1e43
110 changed files with 36 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

11
bots/youtube/readme.md Normal file
View file

@ -0,0 +1,11 @@
# Youtube bot
Youtube bot is a Zulip bot that can fetch first video from youtube
search results for a specified term. To use youtube bot you can simply
call it with `@mention-bot` followed by a command. Like this:
```
@mention-bot <search term>
```
![example usage](assets/screen.png)

31
bots/youtube/youtube.py Normal file
View file

@ -0,0 +1,31 @@
# See readme.md for instructions on running this bot.
import requests
from bs4 import BeautifulSoup
class YoutubeHandler(object):
def usage(self):
return '''
This bot will return the first Youtube search result for the give query.
'''
def handle_message(self, message, client, state_handler):
help_content = '''
To use the, Youtube Bot send `@mention-bot search terms`
Example:
@mention-bot funny cats
'''.strip()
if message['content'] == '':
client.send_reply(message, help_content)
else:
text_to_search = message['content']
url = "https://www.youtube.com/results?search_query=" + text_to_search
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
video_id = soup.find(attrs={'class': 'yt-uix-tile-link'})
try:
link = 'https://www.youtube.com' + video_id['href']
client.send_reply(message, link)
except TypeError:
client.send_reply(message, 'No video found for specified search terms')
handler_class = YoutubeHandler