Permalink
Browse files

Initial commit

  • Loading branch information...
z0w0 committed Oct 13, 2012
0 parents commit 9fa333c74761112ebbfb1167cb3e112f357c28a1
Showing with 195 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +19 −0 LICENSE
  3. +88 −0 README.md
  4. +17 −0 bin/atsaty
  5. +43 −0 lib/main.js
  6. +27 −0 package.json
@@ -0,0 +1 @@
+node_modules
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2012, Zack Corr
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,88 @@
+# Atsaty
+
+A tweet says a thousand yeps...
+
+
+Atsaty acts like `yes`, but instead of always outputting yeps,
+it looks up the current mood of English-speaking tweeters on Twitter. If there are more positive
+tweeters than negative, it outputs yep, otherwise it outputs nope.
+
+```sh
+$ atsaty
+y
+y
+y
+...
+```
+
+```js
+var atsaty = require("atsaty");
+
+atsaty(function(err, yep) {
+ if(yep) console.log("Everyone on Twitter seems to be happy");
+ else console.log("Tweeters are crying at the moment");
+});
+
+atsaty("from:z0w0", function(err, yep) {
+ if(yep) console.log("The creator of this pointless thing is happy");
+ else console.log("The creator is sad, T__T");
+});
+```
+
+## Installation
+
+```sh
+npm install -g atsaty
+```
+
+## Usage
+
+```
+atsaty --help
+
+ Usage: atsaty [options]
+
+ Options:
+
+ -h, --help output usage information
+ -V, --version output the version number
+ -y, --yep <msg> Message to output for yep
+ -n, --nope <msg> Message to output for nope
+
+```
+
+### Examples
+
+```sh
+$ atsaty
+y
+y
+y
+...
+```
+
+```sh
+$ atsaty from:z0w0
+n
+n
+n
+...
+```
+
+## API
+
+### atsaty([user,] cb)
+
+Uses the [Twitter Search API](https://dev.twitter.com/docs/using-search)
+and negative / positive mood detection to figure out how Twitter is currently feeling.
+If `user` is provided, then it will check the mood of a specific Twitter user
+instead of the entire Twitter community.
+
+The callback will be called with an error or `null` as its first argument,
+`false` as its second if there is no positive tweets or there
+are more negative tweets than positive ones, otherwise it calls with a second
+argument of `true`.
+
+## License
+
+The project is MIT licensed. See `LICENSE` for more details.
@@ -0,0 +1,17 @@
+#!/usr/bin/env node
+
+var atsaty = require(".."),
+ pkg = require("../package.json"),
+ program = require("commander");
+
+program
+ .version(pkg.version)
+ .option("-y, --yep <msg>", "Message to output for yep")
+ .option("-n, --nope <msg>", "Message to output for nope")
+ .parse(process.argv);
+
+atsaty(program.args.join(" "), function(err, yep) {
+ var msg = yep ? (program.yep || "y") : (program.nope || "n");
+
+ while(true) console.log(msg);
+});
@@ -0,0 +1,43 @@
+var request = require("request");
+var sentiment = require("sentiment");
+var qs = require("querystring");
+var async = require("async");
+
+module.exports = function(a, b) {
+ var query, cb;
+
+ if("function" === typeof a) {
+ cb = a;
+ } else if("function" === typeof b) {
+ query = a;
+ cb = b;
+ }
+
+ request({
+ uri: "http://search.twitter.com/search.json?" + qs.stringify({
+ q: query && query !== "" ? query.toString() : ":) OR :(",
+ lang: "en"
+ }),
+ json: true
+ }, function(err, res, data) {
+ if(err || !data || !data.results) return cb(err, false);
+
+ var results = data.results;
+ var length = results.length;
+ var yeps = 0;
+ var nopes = 0;
+
+ async.forEach(results, function(result, next) {
+ sentiment(result.text, function(err, result) {
+ if(result.score < 1) nopes++;
+ else yeps++;
+
+ next(err);
+ });
+ }, function(err) {
+ if(err) return cb(err, false);
+
+ cb(null, yeps >= nopes);
+ });
+ });
+};
@@ -0,0 +1,27 @@
+{
+ "name": "atsaty",
+ "description": "A tweet says a thousand yeps",
+ "tags": ["twittwer", "tweet", "yep", "nope"],
+ "version": "0.0.1",
+ "author": "Zack Corr <zack@z0w0.me>",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/z0w0/atsaty.git"
+ },
+ "bugs": {
+ "url": "http://github.com/z0w0/atsaty/issues"
+ },
+ "main": "./lib/main",
+ "bin": {
+ "atsaty": "bin/atsaty"
+ },
+ "dependencies": {
+ "commander": "1.0.x",
+ "request": "2.11.x",
+ "sentiment": "0.1.x",
+ "async": "0.1.xx"
+ },
+ "engines": {
+ "node": ">= 0.6.x"
+ }
+}

0 comments on commit 9fa333c

Please sign in to comment.