Beemind

Posted by chronologos, Last update 7 days ago

Post to Beeminder

Update multiple data points simultaneously using a drafts note. First line must be # Beeminder Template. Each line after that represents a single goal to update in the format goal datapoint comment. Comment may be left out. e.g. sleepmore 1.

Steps

  • script

    base_url = "https://www.beeminder.com/api/v1/"
    
    var credential = Credential.create("Beeminder", "Salvation for akratic data nerds.");
    
    credential.addTextField("username", "Username");
    credential.addPasswordField("auth_token", "Auth Token");
    
    // Populate from https://www.beeminder.com/api/v1/auth_token.json
    credential.authorize();
    
    function main() {
    	text = editor.getText()
    	var lines = text.split("\n");
    	if (lines[0] != "# Beeminder Template") {
    		alert("not the correct template")
    		return
    	}
    	for (let line of lines.slice(1)) {
    		dp = parseLine(line)
    		updateOne(dp[0], dp[1], dp[2])
    	}
    }
    
    // returns datapoint which is array[3] of (string goal, int datapoint, string comment)
    function parseLine(l) {
    	token = l.split(" ")
    	if (token.length == 2) {
    		token.push("") // Empty comment
    	}
    	if (token.length != 3){
    		throw "Malformatted line, stopping here"
    	}
    	return [token[0], token[1], token[2]]
    }
    
    function updateOne(goal, val, comment) {
    	http = HTTP.create();
    	var response = http.request({
    		"url": base_url+"/users/"+ credential.getValue("username")+"/goals/" + goal + "/datapoints.json",
    		"method": "POST",
    		"data": {
    		"value": val,
    		"comment": comment,
    		"auth_token": credential.getValue("auth_token")
    		},
    		"headers": {
    		// "auth_token": extra_headers["auth_token"]
    		}
    	});
    	if (response.success) {}
    	else {
    	  alert(response.statusCode);
    	  alert(response.error);
    	}
    }
    main()

Options

  • After Success Default
    Notification Info
    Log Level Info
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.