Skip to content

Instantly share code, notes, and snippets.

@lifewinning
Created March 29, 2016 13:32
Show Gist options
  • Save lifewinning/5007491ddf75b9d29512 to your computer and use it in GitHub Desktop.
Save lifewinning/5007491ddf75b9d29512 to your computer and use it in GitHub Desktop.
Push URLs posted in a given Slack channel to Pinboard
from flask import Flask, request
import pinboard, urllib2
from bs4 import BeautifulSoup
app = Flask(__name__)
@app.route("/",methods=["POST"])
def slackin():
data = request.form
url = []
tag = []
#parse slack message text with lazy queries
list_text = data['text'].encode('utf-8').split(' ')
for l in list_text:
if l.startswith('<http'):
l = l.replace('<','').replace('>','')
url.append(l)
#hacky way to add tags if you want to use tags in chat
if l.startswith('#'):
l = l.replace('#','').encode('utf-8')
tag.append(l)
else:
desc.append()
# if listening on a Slack channel with other chatter, don't try to parse any chats that don't have URLS
if url[0]:
soup = BeautifulSoup(urllib2.urlopen(url[0]))
if soup.title.name is None:
title = url[0]
else:
title = soup.title.string
# who added this to your pinboard
tag.append(data['user_name'].encode('utf-8'))
pin_key = "YOUR PINBOARD KEY HERE KIND STRANGER READING MY CODE"
pb = pinboard.Pinboard(pin_key)
addpost = pb.posts.add(url = url[0], description = title, tags = tag, extended = data['text'].encode('utf-8'))
# not ideal but for now this is fine, like a dog drinking coffee surrounded by fire is fine this is fine
if addpost:
return 'added' + url[0]
else:
return 'not added, you are a bad human being'
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment