Skip to content
Browse files

First commit.

  • Loading branch information...
0 parents commit 3956ecad33bcb2f2fc2937630cd0fd79a969de64 @paddyforan committed
Showing with 100 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +8 −0 app.yaml
  3. +47 −0 index.html
  4. +43 −0 main.py
2 .gitignore
@@ -0,0 +1,2 @@
+*.swp
+*.pyc
8 app.yaml
@@ -0,0 +1,8 @@
+application: gitwatch
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+ - url: /.*
+ script: main.py
47 index.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+
+ <title>GitWatch</title>
+
+ <meta name="description" content="A live feed of Github repositories.">
+ <meta name="viewport" content="width=1024, user-scalable=no">
+</head>
+<body>
+ <h1>Commits</h1>
+ <ul id="commits"></ul>
+<!-- Grab CDN jQuery, with a protocol relative URL; fall back to local if offline -->
+<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
+<script>window.jQuery || document.write('<script src="jquery-1.7.min.js"><\/script>')</script>
+<script type="text/javascript" src="/_ah/channel/jsapi"></script>
+
+<script>
+function onOpened() {
+ console.log("OPENED");
+}
+
+function onMessage(data) {
+ console.log("Message: "+JSON.stringify(data));
+}
+
+function onError(err) {
+ console.log("Error: "+JSON.stringify(err));
+}
+
+function onClose() {
+ console.log("CLOSED");
+}
+
+$(function() {
+ channel = new goog.appengine.Channel('{{ token }}');
+ socket = channel.open();
+ socket.onopen = onOpened;
+ socket.onmessage = onMessage;
+ socket.onerror = onError;
+ socket.onclose = onClose;
+});
+</script>
+
+</body>
+</html>
43 main.py
@@ -0,0 +1,43 @@
+from google.appengine.api import channel
+from google.appengine.api import memcache
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import template
+from google.appengine.ext.webapp.util import run_wsgi_app
+from django.utils import simplejson
+import time
+import logging
+import httplib
+
+class MainPage(webapp.RequestHandler):
+ def get(self):
+ now = time.time()
+ req_id = str(now) + self.request.remote_addr
+ req_id = req_id[0:63]
+ new_token = channel.create_channel(req_id)
+ expires = now + (60 * 60 * 2)
+ tokens = memcache.get("tokens")
+ valid_tokens = []
+ if tokens is None:
+ tokens = []
+ for id, token, expiration in tokens:
+ logging.info(id)
+ logging.info(token)
+ logging.info(expiration)
+ if expiration > time.time():
+ valid_tokens.append((id, token, expiration))
+ valid_tokens.append((req_id, new_token, expires))
+ memcache.set("tokens", valid_tokens)
+
+ template_values = {"token": new_token}
+
+ self.response.out.write(template.render('index.html', template_values))
+
+application = webapp.WSGIApplication([
+ ('/', MainPage)
+ ])
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == "__main__":
+ main()

0 comments on commit 3956eca

Please sign in to comment.
Something went wrong with that request. Please try again.