Skip to content

Instantly share code, notes, and snippets.

@mtellin
Last active March 22, 2019 19:40
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 mtellin/75cf794c9d40648063ef3d3554e1a0f1 to your computer and use it in GitHub Desktop.
Save mtellin/75cf794c9d40648063ef3d3554e1a0f1 to your computer and use it in GitHub Desktop.
Post to my home Slack channel when a new version of rclone is released. Uses kvdb.io as the key/value store for current version.
import requests
import os
from bs4 import BeautifulSoup
# Set environment variables for the following items
slackToken = os.environ['SLACK_TOKEN']
kvdbId = os.environ['KVDB_ID']
rcloneLogo = os.environ['RCLONE_LOGO']
# Pull the rClone page and use BeautifulSoup to parse
page = requests.get('http://rclone.org/downloads')
soup = BeautifulSoup(page.text, 'html.parser')
version_tag = soup.find(id='rclone-download-hahahugoshortcode-0xc4203b8f00-1-hbhb')
versionString = version_tag.text
webVersion = float(versionString.split('v')[1])
session = requests.get('https://kvdb.io/{}/version'.format(kvdbId))
currentVersion = session.json()
if webVersion > currentVersion:
slackData = {
'channel': '#backups',
'text': 'Woohoo, there is a new rclone version: ' + str(webVersion),
'username': 'rclone',
'icon_url': rcloneLogo,
'token': slackToken
}
response = requests.post('https://slack.com/api/chat.postMessage', slackData)
# Update KVDB with the new rclone version
kvdbData = str(webVersion)
response = requests.post('https://kvdb.io/{}/version'.format(kvdbId), kvdbData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment