Skip to content

Instantly share code, notes, and snippets.

@rdmurphy
Last active December 28, 2015 11:29
Show Gist options
  • Save rdmurphy/7493576 to your computer and use it in GitHub Desktop.
Save rdmurphy/7493576 to your computer and use it in GitHub Desktop.
It's really easy to provide a hook into hitting a URL from a Google Spreadsheet. Here's how we do it. Stupid simple Flask app hangs out on Heroku and listens for the URL hit, which prompts the script to do the deed.
import os
from flask import Flask
from prepare_data import prepare_data
app = Flask(__name__)
@app.route('/')
def hello():
return 'Not giving you nothin\''
@app.route('/update')
def update():
prepare_data()
return 'Away we go!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [{name: 'Submit', functionName: 'update'}];
ss.addMenu('Update', menuEntries);
}
function update() {
var response = UrlFetchApp.fetch('<url-to-be-visited>');
if (response.getResponseCode() === 200) {
SpreadsheetApp.getUi().alert('The update was a SUCCESS!');
} else {
SpreadsheetApp.getUi().alert('It appears something went wrong.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment