Permalink
Browse files

Updating configs and readme.

  • Loading branch information...
1 parent 6812244 commit 4343abdb8442019a1dbaeb2001dbce583b869039 @kevineder committed Oct 7, 2012
Showing with 20 additions and 44 deletions.
  1. +4 −2 README.md
  2. +4 −9 config.ini.sample
  3. +12 −33 static/main.js
View
@@ -1,20 +1,22 @@
PyCoffeeD
=========
-PyCoffeeD is a fork of the CoffeeD project, rewritten in Python. Like the original CoffeeD, it measures the number of cups of coffee remaining in a coffee pot, using a USB scale.
+PyCoffeeD is a fork of the CoffeeD project, rewritten in Python. Like the original CoffeeD, it measures the number of cups of coffee remaining in a coffee pot, using a USB scale and [StatsD](https://github.com/etsy/statsd). It can also tweet.
This fork was created in tandem with the original CoffeeD author, [morria](https://github.com/morria).
Tested against [DYMO by Pelouze 10 lb. USB Mailing Scale](http://www.amazon.com/DYMO-Pelouze-lb-Mailing-Scale/dp/B001B0EYSW/)
Installation
------------
+These instructions assume you already have a [StatsD](https://github.com/etsy/statsd)/[Graphite](http://graphite.wikidot.com/) server in place.
* Clone the repo.
* Install the dependencies
`sudo pip install -r ./requirements.txt`
* Update CoffeeD.py with the vendor / product ID of your USB scale. Find this info using:
`sudo lsusb -v`
-* Copy config.ini.sample to config.ini, and update it with your Twitter info, url to your StatsD server, and the url to your webapp.
+* Copy config.ini.sample to config.ini and update it with your Twitter info, StatsD server URL, and webapp URL.
+* Copy static/config.js.sample to static/config.js and update it with your Graphite server URL, Graphite bucket key, and webapp URL.
Run the web app
------
View
@@ -1,16 +1,11 @@
[StatsD]
-url: your.statsd.server.example.com
+url: statsd.server.example.com
port: 8125
-[Graphite]
-url: http://graphite.web.interface.com
-bucket: stats.gauges.coffee.cups
-
[Twitter]
-consumer_key: xxxxxxxxxxx
-consumer_secret: xxxxxxxxxxxxx
-app_name: "Your App"
-screen_name: YourTwitterHandle
+consumer_key: XXXXXXXXXXXXXX
+consumer_secret: XXXXXXXXXXXXXXXXXXXXXXX
+app_name: "Coffee Machine"
[PyCoffeeD]
url: http://192.168.1.101:5000
View
@@ -7,44 +7,23 @@ $(function() {
function updateStats() {
$("#graph").prop("src", config["graphite-url"] + "/render/?width=612&height=350&_salt=1349559210.774&target=" + config["bucket"] + "&yMax=10.9&from=-2hour&yMin=0&hideGrid=true&hideAxes=false&graphOnly=false&title=Cups&hideLegend=true&tz=America/New_York&lineWidth=2&bgcolor=white&fgcolor=black");
- //$.getJSON(config["pycoffeed-url"] + "/stats", function(json) {
- // if (json && json.hasOwnProperty('cups')) {
+ $.getJSON(config["pycoffeed-url"] + "/stats", function(json) {
+ if (json && json.hasOwnProperty('cups')) {
- // $(".hero-unit h1").text("There are " + json['cups'] + " cups of coffee left.");
- // $(".hero-unit h2").text("(That's " + json['caffeine'] + " of caffeine.)");
- // $("#blocker").hide();
- // }
- // else {
- // $(".hero-unit h1").text("There was a problem retrieving the data.");
- // $(".hero-unit h2").text("");
- // $("#blocker").hide();
- // }
- //});
-
- $.getJSON("/getStats.php", function(json) {
- json = json[0];
- if (json && json.hasOwnProperty('datapoints') && json.datapoints.length > 0) {
-
- //For some reason graphite occasionally returns null for the most recent statistic.
- var cups = json['datapoints'][json.datapoints.length-1][0];
-
- if (!cups) {
- cups = json['datapoints'][json.datapoints.length-2][0];
- }
-
- cups = Math.round(100 * cups)/100;
- var caffeine = Math.round(100 * ((cups * 8)/8.5) * 49)/100;
-
- $(".hero-unit h1").text("There are " + cups + " cups of coffee left.");
- $(".hero-unit h2").text("(That's ~" + caffeine + "mg of caffeine.)");
+ $(".hero-unit h1").text("There are " + json['cups'] + " cups of coffee left.");
+ $(".hero-unit h2").text("(That's " + json['caffeine'] + " of caffeine.)");
$("#blocker").hide();
}
else {
- $(".hero-unit h1").text("There was a problem retrieving the data.");
- $(".hero-unit h2").text("");
- $("#blocker").hide();
+ error();
}
- });
+ }).error(error);
+
+}
+function error() {
+ $(".hero-unit h1").text("There was a problem retrieving the data.");
+ $(".hero-unit h2").text("");
+ $("#blocker").hide();
}

0 comments on commit 4343abd

Please sign in to comment.