Instantly share code, notes, and snippets.

Embed
What would you like to do?
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