Commits

Rune Halvorsen committed b964bec

Added user name and goodness value to output

Comments (0)

Files changed (3)

geist/__init__.py

 
 GOODNESS = [
     "cool", "nice", "good", "fast", "slick", "awesome", "rules",
-    "pretty", "powerful", "solid", "beautiful",
+    "pretty", "powerful", "solid", "beautiful", "love"
 ]
 
 BADNESS = [
-    "bad", "suck", "shit", "crap", "aweful", "slow", "ugly",
-    "shit", "frustrating",
+    "bad", "suck", "shit", "crap", "awful", "slow", "ugly",
+    "shit", "frustrating", "hate",
 ]
 
 
 def tweets():
     tweets = stream.get_tweets()
     print "pending", len(tweets)
+
+    for tweet in tweets:
+        subject=tweet["text"].lower()
+        tweet["mood"] = 0
+
+        if [e for e in GOODNESS if e in subject]:
+            tweet["mood"] += 1
+        elif [e for e in BADNESS if e in subject]:
+            tweet["mood"] -= -1
+
     return {"tweets": tweets}
 
 
-    if tweets:
-        subject=tweet["text"].lower()
-        if [e for e in GOODNESS if e in subject]:
-            tweet["mood"] = 1
-        elif [e for e in BADNESS if e in subject]:
-            tweet["mood"] = -1
-        else:
-            tweet["mood"] = 0
-
-
-
 from bottle import static_file
 @route('/static/:filename')
 def server_static(filename):
         if not options.password:
             parser.error("Password required")
 
-
     parser.error("Bad User")
 
 

geist/static/style.css

     height: 64px;
     border: solid thin black;
 }
+
+.screen_name {
+    text-decoration: underline;
+}

geist/templates/index.tpl

     }
 
     var li = document.createElement("li");
-    var span = document.createElement("span");
-    span.textContent = tweet.text;
+
+    var name = document.createElement("span");
+    name.className = "screen_name";
+    name.textContent = tweet.user.screen_name + " (mood: " + tweet.mood  + "): ";
+
+    var text = document.createElement("span");
+    text.textContent = tweet.text;
     var img = document.createElement("img");
     img.src = tweet.user.profile_image_url;
 
-    li.appendChild(img)
-    li.appendChild(span)
+    li.appendChild(img);
+    li.appendChild(name);
+    li.appendChild(text);
 
     li.style.backgroundColor = tweet.user.profile_background_color;
     li.style.color = tweet.user.profile_text_color;