Commits

Rune Halvorsen  committed 660d662

Moved scripts and settings into separate files

  • Participants
  • Parent commits cca362d

Comments (0)

Files changed (4)

File geist/__init__.py

 from os.path import dirname, join
 from tweetstream import TrackStream
 import bottle
-from bottle import route, run, view, debug
+from bottle import route, run, view, debug, static_file
+
 
 from .twitter import TrackStreamThread
 
 @route('/')
 @view('index')
 def index():
-    return {"update_interval": update_interval}
+    return {}
+
 
 @route('/settings')
 @view('settings')
     return {"tweets": tweets}
 
 
-from bottle import static_file
+@route('/config')
+@view('config')
+def config():
+    return {"update_interval": update_interval}
+
+
 @route('/static/:filename')
 def server_static(filename):
     return static_file(filename, root=join(appdir, "static"))
 
 
 
+
+
 def parse_options():
     parser = optparse.OptionParser()
     parser.add_option("-u", "--user", dest="user")
 
 
     words = ["opera dragonfly"]
-    words = ["love","hate","bieber"]
+    words = ["opera"]
+    #words = ["love","hate","bieber"]
 
     global stream
     stream = TrackStreamThread("xxx", "yyy", words)

File geist/static/script.js

+window.pending_request = false;
+window.pending_tweets = [];
+window.timerid = window.setInterval(on_timer, window.update_interval*1000);
+
+function on_timer() {
+    if (pending_tweets.length) {
+        var tweet = pending_tweets.shift();
+        render_tweet(tweet);
+    }
+    else if (!pending_request) {
+        get_tweets();
+    }
+}
+
+function get_tweets() {
+    pending_request = true;
+    var conn = new XMLHttpRequest();
+    conn.open("GET", "/tweets", false);
+    conn.onreadystatechange = rs_handler;
+    conn.send(null);
+}
+
+function rs_handler() {
+    conn = this;
+    if (conn.readyState == 4) {
+        on_tweets(JSON.parse(conn.responseText), conn);
+    }
+}
+
+function on_tweets(data) {
+    pending_request = false;
+    pending_tweets = pending_tweets.concat(data.tweets);
+}
+
+function render_tweet(tweet) {
+    var ol = document.querySelector("#tweets");
+    if (ol.childNodes.length>5) {
+        ol.removeChild(ol.childNodes[ol.childNodes.length-1]);
+    }
+
+    var li = $.fromZen("li.tweet>img+span.screen_name+span.text");
+    li.find("img").attr("src", tweet.user.profile_image_url);
+    li.find(".screen_name").text(tweet.user.screen_name + ": ");
+    li.find(".text").text(tweet.text);
+
+    li.style("background-color", tweet.user.profile_background_color);
+    li.style("color", tweet.user.profile_text_color);
+
+    $("#tweets").insert(li);
+}
+
+window.onload = function() {
+    window.$ = window.Unbose;
+    on_timer();
+};
+

File geist/templates/config.tpl

+window.update_interval = {{ update_interval }};

File geist/templates/index.tpl

 <!doctype html>
 <link rel="stylesheet" href="/static/style.css" />
+<script src="/config"></script>
+<script src="/static/script.js"></script>
 <script src="/static/unbose.js"></script>
-<script>
-window.$ = window.Unbose
-
-window.update_interval = {{ update_interval }};
-window.pending_request = false;
-window.pending_tweets = [];
-window.timerid = window.setInterval(on_timer, window.update_interval*1000);
-
-function on_timer() {
-    if (pending_tweets.length) {
-        var tweet = pending_tweets.shift();
-        render_tweet(tweet);
-    }
-    else if (!pending_request) {
-        get_tweets();
-    }
-}
-
-function get_tweets() {
-    pending_request = true;
-    var conn = new XMLHttpRequest();
-    conn.open("GET", "/tweets", false);
-    conn.onreadystatechange = rs_handler;
-    conn.send(null)
-}
-
-function rs_handler() {
-    conn = this;
-    if (conn.readyState == 4) {
-        on_tweets(JSON.parse(conn.responseText), conn);
-    }
-}
-
-function on_tweets(data) {
-    pending_request = false;
-    pending_tweets = pending_tweets.concat(data.tweets);
-}
-
-function render_tweet(tweet) {
-    var ol = document.querySelector("#tweets");
-    if (ol.childNodes.length>5) {
-        ol.removeChild(ol.childNodes[ol.childNodes.length-1]);
-    }
-
-    var li = $.fromZen("li.tweet>img+span.screen_name+span.text")
-    li.find("img").attr("src", tweet.user.profile_image_url);
-    li.find(".screen_name").text(tweet.user.screen_name + ": ");
-    li.find(".text").text(tweet.text);
-
-    li.style("background-color", tweet.user.profile_background_color);
-    li.style("color", tweet.user.profile_text_color);
-
-    $("#tweets").insert(li);
-}
-
-window.onload = on_timer;
-
-</script>
 <h1>Tweets</h1>
 <ol id="tweets"></ol>