Skip to content

Instantly share code, notes, and snippets.

@Enchufa2
Last active September 24, 2020 16:58
Show Gist options
  • Save Enchufa2/bd217565ec9ecc94a4f5 to your computer and use it in GitHub Desktop.
Save Enchufa2/bd217565ec9ecc94a4f5 to your computer and use it in GitHub Desktop.
This snippet monitors your R packages' CRAN Package Check Results page and notifies you by email if there are any changes.
#remotes::install_github("ropensci/cchecks")
library(cchecks)
myaddress <- whoami::email_address()
# cchn_register(myaddress)
pkgs <- cch_maintainers(sub("@", "_at_", myaddress))$data$packages
msgs <- c("warn", "error")
rules <- lapply(pkgs$package, function(pkg) list(package=pkg))
rules <- do.call(c, lapply(msgs, function(status)
lapply(rules, modifyList, list(status=status))))
cchn_rules_add(rules, myaddress)
#!/usr/bin/env python2
# coding=UTF8
# Author: Iñaki Ucar <i.ucar86@gmail.com>
# Description: Track your R packages' CRAN Package Check Results page
from urllib2 import urlopen
from itertools import izip, izip_longest
import xml.etree.ElementTree as ET
import smtplib, pickle, re, sys, os
# set -v to get debug output
debug = False
if len(sys.argv) == 2 and sys.argv[1] == '-v':
debug = True
# configuration (set the proper values)
PACKAGES = ['pkg1', 'pkg2']
FROM = 'dummy@dummy'
TO = ['dummy@dummy', 'other@other']
SMTP_SERVER = 'localhost'
SUBJECT = '[cran-check-watcher] New package checks on CRAN'
URL = 'https://cran.r-project.org/web/checks/check_results_%s.html'
PASS = None
PATH = os.path.dirname(os.path.realpath(__file__))
LOG = os.path.join(PATH, "cran-check-watcher.log")
# Python 2.6 compatibility
def compress(data, selectors):
return (d for d, s in izip(data, selectors) if s)
# table retrieval
table = []
for pkg in PACKAGES:
try: html = urlopen(URL % pkg, timeout=30).read()
except: break
xtree = ET.fromstring(html.replace('&nbsp;', '&#160;'))
xtable = xtree[1].find('{http://www.w3.org/1999/xhtml}table')
for row in xtable[1:]:
table.append([pkg])
for field in compress(row, [1, 1, 0, 0, 0, 1, 0]):
table[-1].append(re.sub('<[^<]+>', '', ET.tostring(field)).strip())
try:
last_table = pickle.load(open(LOG, 'rb'))
except:
last_table = table
pickle.dump(table, open(LOG, 'wb'))
# comparison
TEXT = 'New results:'
DEBUG = ''
for row, last_row in izip_longest(table, last_table):
new_check = False
if row:
new_line = '%s:\t%s\t%s\t %s' % (row[0], row[2], row[3], row[1])
if row != last_row:
new_check = True
TEXT += '\r\n ' + new_line
else:
new_line = '%s:\t%s\t%s\t %s' % (last_row[0], last_row[2], last_row[3], last_row[1])
DEBUG += '%s\t%s\n' % (new_check, new_line)
if debug:
print DEBUG
# notification
if TEXT != 'New results:':
message = '''\
From: %s
To: %s
Subject: %s
%s
''' % (FROM, ', '.join(TO), SUBJECT, TEXT)
server = smtplib.SMTP(SMTP_SERVER)
if PASS != None:
server.login(FROM, PASS)
server.sendmail(FROM, TO, message)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment