Created
May 25, 2017 11:15
-
-
Save palazzem/ae75bd289aaf36076d44fae28f3f6933 to your computer and use it in GitHub Desktop.
[datadog] kickstarter_metrics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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