Skip to content

Instantly share code, notes, and snippets.

@aviskase
Last active May 16, 2020 07:39
Show Gist options
  • Save aviskase/079fda60adaa0c74e37c84089e4bb1ae to your computer and use it in GitHub Desktop.
Save aviskase/079fda60adaa0c74e37c84089e4bb1ae to your computer and use it in GitHub Desktop.
Google Apps Script: create task in Amazing Marvin when new version of library appears in pypi
var TARGET_EMAIL = '<AMAZING_MARVIN_IMPORT_EMAIL>';
var LIBRARY_NAME = '<SOME_LIBRARY>'
var URL_LIBRARIES_IO = 'https://libraries.io/pypi/LIBRARY_NAME/versions.atom'
var CATEGORY_OR_PROJECT = '<CATEGORY OR PROJECT IN AMAZING MARVIN>'
function parseXml() {
var props = PropertiesService.getScriptProperties();
var xml = UrlFetchApp.fetch(URL_LIBRARIES_IO).getContentText();
var document = XmlService.parse(xml);
var root = document.getRootElement();
var atom = XmlService.getNamespace('http://www.w3.org/2005/Atom');
var entries = document.getRootElement().getChildren('entry', atom);
for (var i = 0; i < entries.length; i++) {
var title = entries[i].getChild('title', atom).getText();
var prop_title = props.getProperty(title);
if(!prop_title) {
Logger.log('New version found %s', title);
var link = entries[i].getChild('link', atom).getAttribute('href').getValue();
props.setProperty(title, '1')
sendEmail(title, link);
}
}
}
function sendEmail(title, link) {
var subject = Utilities.formatString('New version [%s %s](%s) #"%s" +today', LIBRARY_NAME, title, link, CATEGORY_OR_PROJECT);
GmailApp.sendEmail(TARGET_EMAIL, subject, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment