Skip to content

Instantly share code, notes, and snippets.

@palazzem
Created May 25, 2017 11:15
Show Gist options
  • Save palazzem/ae75bd289aaf36076d44fae28f3f6933 to your computer and use it in GitHub Desktop.
Save palazzem/ae75bd289aaf36076d44fae28f3f6933 to your computer and use it in GitHub Desktop.
[datadog] kickstarter_metrics.py
import requests
from datetime import datetime, timedelta
from datadog import initialize, statsd
options = {
'api_key':'your_datadog_key_here',
}
# don't use a trailing slash
PROJECT_TAG = 'barbarians_game'
KICKSTARTER_LINK = "https://www.kickstarter.com/projects/tabulagames/barbarians-the-invasion"
URL = "{}/stats.json?v=1".format(KICKSTARTER_LINK)
# choose your end date
END_DATE = datetime(2017, 5, 24, 0, 0)
try:
# get the value
data = requests.get(URL).json()['project']
pledged = float(data['pledged'])
backers = float(data['backers_count'])
# compute campaign ending time
now = datetime.datetime.today()
days_left = (ends - now).days + 1
# publish the gauge
initialize(**options)
statsd.gauge('kickstarter.pledged', pledged, tags=[PROJECT_TAG])
statsd.gauge('kickstarter.backers_count', backers, tags=[PROJECT_TAG])
statsd.gauge('kickstarter.days_left', days_left, tags=[PROJECT_TAG])
print("Gauges published!")
except Exception:
print("Nothing to do because the API wasn't ready")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment