Created
February 6, 2015 22:40
-
-
Save soerface/ee89056fc857a3f37e05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import httplib | |
import json | |
from influxdb import InfluxDBClient | |
SERVER = 'flipdot.org' | |
API = { | |
'status': '/spacestatus/status.json', | |
} | |
INFLUXDB_HOST = 'localhost' | |
INFLUXDB_PORT = 8086 | |
INFLUXDB_USER = 'flipdot' | |
INFLUXDB_PASSWORD = 'PASSWORD' | |
INFLUXDB_DB = 'flipdot' | |
conn = httplib.HTTPConnection(SERVER) | |
conn.request('GET', API['status']) | |
r = conn.getresponse() | |
data = json.loads(r.read()) | |
conn.close() | |
try: | |
known_users = len(data['known_users']) | |
except KeyError: | |
known_users = 0 | |
try: | |
unknown_users = data['unknown_users'] | |
except KeyError: | |
unknown_users = 0 | |
all_users = known_users + unknown_users | |
client = InfluxDBClient(INFLUXDB_HOST, INFLUXDB_PORT, INFLUXDB_USER, INFLUXDB_PASSWORD, INFLUXDB_DB) | |
#client.create_database('flipdot') | |
if len(sys.argv) < 2 or sys.argv[1] != 'dry': | |
client.write_points([{ | |
'points': [[all_users, known_users, unknown_users]], | |
'name': 'users', | |
'columns': ['all_users', 'known_users', 'unknown_users'], | |
}]) | |
else: | |
print 'dry run, didnt write too db' | |
# TODO: integrate power consumption in space api | |
conn = httplib.HTTPConnection('infragelb.de') | |
conn.request('GET', '/flipdot-power/') | |
power_consumption = int(conn.getresponse().read().split(',')[-1].strip()) | |
if len(sys.argv) < 2 or sys.argv[1] != 'dry': | |
client.write_points([{ | |
'points': [[power_consumption]], | |
'name': 'power_consumption', | |
'columns': ['value'], | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment