Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python wrapper for Beeminder API requests (goal datapoints ONLY)
"""
beeminder_client.py ~ Python wrapper for Beeminder API requests (goal datapoints ONLY)
Usage:
from beeminder_client import BeeminderClient
beeminder = BeeminderClient()
timestamp = get_epoch_time_in_seconds()
params = {
'timestamp': timestamp,
'comment': '1 gizmos completed (Cron entry on %s)' % (get_date_string(), ),
'value': 1,
'requestid': 'cron-goalName-%s' % (timestamp, )
}
response = beeminder.post('goalName', params=params)
print response.body
License:
http://www.wtfpl.net/
"""
import unirest
beeminder_username = 'USERNAME HERE'
beeminder_token = 'TOKEN HERE'
class BeeminderClient(object):
_params = {
'auth_token': beeminder_token,
}
def _build_params(self, new_params):
for k, v in self._params.items():
new_params[k] = v
return new_params
def _build_url(self, goal_str):
return "https://www.beeminder.com/api/v1/users/%s/goals/%s/datapoints.json" % (beeminder_username, goal_str, )
def get(self, goal_str, params={}):
url = self._build_url(goal_str)
params = self._build_params(params)
return unirest.get(url, params=params)
def put(self, goal_str, params={}):
url = self._build_url(goal_str)
params = self._build_params(params)
return unirest.put(url, params=params)
def patch(self, goal_str, params={}):
url = self._build_url(goal_str)
params = self._build_params(params)
return unirest.patch(url, params=params)
def post(self, goal_str, params={}):
url = self._build_url(goal_str)
params = self._build_params(params)
return unirest.post(url, params=params)
def delete(self, goal_str, params={}):
url = self._build_url(goal_str)
params = self._build_params(params)
return unirest.delete(url, params=params)
@dreeves

This comment has been minimized.

Show comment
Hide comment
@dreeves

dreeves Feb 25, 2014

Thanks for sharing this! If I make you an owner at github.com/beeminder would you want to put this there?

dreeves commented Feb 25, 2014

Thanks for sharing this! If I make you an owner at github.com/beeminder would you want to put this there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment