Skip to content

Instantly share code, notes, and snippets.

@raivatshah
Created July 3, 2019 10:30
Show Gist options
  • Save raivatshah/ff42b14616aeebd58e4ef590ba5a9171 to your computer and use it in GitHub Desktop.
Save raivatshah/ff42b14616aeebd58e4ef590ba5a9171 to your computer and use it in GitHub Desktop.
Simple Telegram Bot to automate the process of obtaining Outline.com links.
"""
Simple Telegram Bot to automate the process of obtaining Outline.com links.
Created by Raivat Shah in 2019.
"""
# Imports
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# Logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
# Command Handlers. Usually take two arguments: bot and update.
def start(update, context):
context.bot.send_message(chat_id=update.message.chat_id, text="Welcome! Pls send '/read + url of the article' to obtain Outline.com link")
def read(update, context):
# Processing Outline
browser = webdriver.Chrome('directory_of_chrome_driver')
browser.get('https://www.outline.com')
linkbar = browser.find_element_by_id('source')
linkbar.send_keys(context.args) # pass in the link from the argument
linkbar.send_keys(Keys.ENTER)
time.sleep(10)
# send the link back
context.bot.send_message(chat_id=update.message.chat_id, text=browser.current_url)
def main():
# Create updater and pass in Bot's auth key.
updater = Updater(token='your_bot_auth_key_here', use_context=True)
# Get dispatcher to register handlers
dispatcher = updater.dispatcher
# answer commands
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('read', read))
# start the bot
updater.start_polling()
# Stop
updater.idle()
if __name__ == '__main__':
main()
@AtilioA
Copy link

AtilioA commented Jul 3, 2020

Is it live somewhere?

@raivatshah
Copy link
Author

Hey! Unfortunately, no! As far as I know, outline has disallowed tools such as selenium to interact with their website.

@AtilioA
Copy link

AtilioA commented Jul 5, 2020

That's a pity! Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment