Skip to content

Instantly share code, notes, and snippets.

@kivantium
Created April 18, 2018 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kivantium/a46d010a4c96e38bcbf6b08e520ee8d7 to your computer and use it in GitHub Desktop.
Save kivantium/a46d010a4c96e38bcbf6b08e520ee8d7 to your computer and use it in GitHub Desktop.
Expand
import json
import re
import time
import arxiv
from slackclient import SlackClient
slack_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
sc = SlackClient(slack_token)
if sc.rtm_connect():
while sc.server.connected is True:
data = sc.rtm_read()
if len(data) > 0:
for item in data:
if item["type"] == "message":
text = item["text"]
channel = item["channel"]
for m in re.finditer("https://arxiv.org/abs/([\w|.]+)", text):
arxiv_id = m.groups()
arxiv_info = arxiv.query(id_list=arxiv_id)[0]
title = arxiv_info["title"]
summary = arxiv_info["summary"]
url = arxiv_info["arxiv_url"]
at = [{
"author_icon": "https://arxiv.org/favicon.ico",
"author_name": "arXiv.org",
"title": title,
"title_link": url,
"text": summary[:140],
"fallback": url,
}]
sc.api_call("chat.postMessage",
channel=channel,
attachments=json.dumps(at))
time.sleep(1)
else:
print("Connection Failed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment