-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_biorxiv.py
51 lines (41 loc) · 1.49 KB
/
driver_biorxiv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from slack_api_functions import slack_api
import configparser
# load config file
bot_config = configparser.RawConfigParser()
bot_config.read("bot.cfg")
bot_token = bot_config.get('slack-bot-config', 'bot_token')
channel = bot_config.get('slack-bot-config', 'channel')
# ================ run the constructor =============== #
bot = slack_api()
# if you need to get the channel id
#channel_info = bot.readSlackConversations("list", payload = {"token":bot_token})
# fill the bot with data
bot.setToken(bot_token)
bot.setChannel(channel)
bot.makePayload()
# post to the slack
import datetime
today = str(datetime.date.today())
thread_header = "*Here are the bioRxiv - Bioinformatics posts from* " + "*" + today + "!*"
bot.makePayload(text=thread_header)
bot.postSlackChat()
# get ts from the last post
bot.makePayload(limit="1")
last_message = bot.readSlackConversations("history")
thread_ts = last_message['messages'][0]['ts']
# add the thread_ts to the global variables and create the base payload
bot.setThreadTS(thread_ts)
bot.setUnfurlLinks('false')
bot.makePayload()
base_payload = bot.getPayload()
# post the feed
import feedparser
import time
NewsFeed = feedparser.parse("http://connect.biorxiv.org/biorxiv_xml.php?subject=bioinformatics")
for entry in NewsFeed.entries:
# add the article to the payload
base_payload['text'] = "*Title:* " + entry['title'].split(".")[0] + '\n' + "*URL:* " + entry['link']
# post
bot.postSlackChat(payload = base_payload)
# sleep for 1s
time.sleep(1)