Skip to content
Browse files

Initial import

  • Loading branch information...
0 parents commit b8a4b41adceffcf8ec196eef22e372434bc192aa @bnmrrs committed
Showing with 196 additions and 0 deletions.
  1. +17 −0 app.yaml.sample
  2. BIN audio/raptor-sound.mp3
  3. BIN audio/raptor-sound.ogg
  4. BIN images/spinner.gif
  5. +132 −0 index.html
  6. +47 −0 main.py
17 app.yaml.sample
@@ -0,0 +1,17 @@
+application: app_name
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /
+ script: main.py
+
+- url: /images
+ static_dir: images
+
+- url: /audio
+ static_dir: audio
+
+- url: /.*
+ script: main.py
BIN audio/raptor-sound.mp3
Binary file not shown.
BIN audio/raptor-sound.ogg
Binary file not shown.
BIN images/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 index.html
@@ -0,0 +1,132 @@
+<html>
+ <head>
+ <title>Calculate your Uncle Dan score</title>
+ <style type="text/css" media="screen">
+ body {
+ font-family:Arial, Helvetica, sans-serif;
+ margin:0;
+ padding:0;
+ }
+
+ #container {
+ padding-top: 150px;
+ margin: 0 auto;
+ width: 1000px;
+ text-align:center;
+ }
+
+ h1 {
+ font-size: 50px;
+ }
+
+ #spinner {
+ display: none;
+ }
+
+ #numdans-wrapper {
+ display: none;
+ font-size: 24px;
+ }
+
+ #numdans-wrapper a {
+ color: #666;
+ }
+
+ #numdans-wrapper p {
+ margin: 0;
+ }
+
+ #tryagain {
+ font-size: 12px;
+ }
+
+ #numdans {
+ font-weight: bold;
+ font-size: 36px;
+ }
+
+ #you {
+ font-weight: bold;
+ font-size: 36px;
+ }
+
+ #footer {
+ }
+
+ #footer a {
+ color: #666;
+ }
+
+ #dan {
+ display: none;
+ position: absolute;
+ right: 0;
+ bottom: 0;
+ }
+ </style>
+
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script src="http://github.com/cowboy/jquery-starwipe/raw/master/jquery.ba-starwipe.min.js"></script>
+ <script src="http://files.www.gethifi.com/posts/konami/konami.js"></script>
+ <script type="text/javascript">
+ $(document).ready(function() {
+ $("q.starwipe").starwipe();
+
+ $(window).konami(function(){
+ $('#dan').slideDown(500, function() {
+ document.getElementById('elRaptorShriek').play();
+ $('#dan').animate({right: $(window).width()+'px'},2500);
+ });
+
+ });
+
+ $('#findout').submit(function(e) {
+ $('#question').hide();
+ $('#spinner').show();
+
+ $.ajax({
+ type: 'POST',
+ url: '/howmany',
+ data: {
+ username: $('#username').val(),
+ },
+ success: function(response) {
+ $('#numdans').text(response.dans);
+ $('#you').text($('#username').val());
+
+ $('#spinner').fadeOut(200, function() {
+ $('#numdans-wrapper').fadeIn(200);
+ });
+ },
+ dataType: 'json'
+ });
+
+ return false;
+ });
+
+ $('#tryagain').click(function() {
+ $('#numdans-wrapper').fadeOut(200, function() {
+ $('#question').fadeIn(200);
+ });
+ return false;
+ });
+ });
+ </script>
+ </head>
+ <body>
+ <div id="container">
+ <h1>How many Uncle Dans are you?</h1>
+ <form action="/" method="post" id="findout">
+ <p id="question">Enter your <input type="text" id="username" placeholder="twitter username" /> and <input type="submit" value="find out."></p>
+ <img src="/images/spinner.gif" id="spinner" />
+ <div id="numdans-wrapper">
+ <p><span id="you"></span> is <span id="numdans"></span> Uncle Dans!</p>
+ <p><a href="#" id="tryagain">Try again</a></p>
+ </div>
+ <p id="footer">Crafted lovingly by <a href="http://bnmrrs.com" class="starwipe">Benjamin Morris</a><br /> As a gift to <a href="http://twitter.com/dannomatic" class="starwipe">Dannomatic</a><br />Powered by <a href="http://klout.com" class="starwipe">Klout</a></p>
+ </form>
+ </div>
+ <img id="dan" src="http://imgur.com/F3rac.png"/>
+ <audio id="elRaptorShriek" preload="auto"><source src="/audio/raptor-sound.mp3" /><source src="/audio/raptor-sound.ogg" /></audio>
+ </body>
+</html>
47 main.py
@@ -0,0 +1,47 @@
+import os
+import cgi
+import logging
+from google.appengine.ext.webapp import template
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import util
+from django.utils import simplejson as json
+from google.appengine.api import urlfetch
+
+
+KLOUT_API_KEY = 'aua78jp2cp7bm65dmuwpv38d'
+
+class MainPage(webapp.RequestHandler):
+ def get(self):
+ path = os.path.join(os.path.dirname(__file__), 'index.html')
+ self.response.out.write(template.render(path, {}))
+
+class HowMany(webapp.RequestHandler):
+ def post(self):
+ dan_url = "http://api.klout.com/1/users/show.json?key="+ KLOUT_API_KEY +"&users=dannomatic"
+ your_url = "http://api.klout.com/1/users/show.json?key="+ KLOUT_API_KEY +"&users=" + cgi.escape(self.request.get('username'))
+
+ dan = urlfetch.fetch(dan_url).content
+ you = urlfetch.fetch(your_url).content
+
+ dan = json.loads(dan)
+ you = json.loads(you)
+
+ try:
+ dan_score = dan['users'][0]['score']['kscore']
+ your_score = you['users'][0]['score']['kscore']
+
+ num_dans = round(your_score / dan_score, 2)
+ except KeyError:
+ num_dans = 0
+
+ self.response.headers['Content-Type'] = 'application/json'
+ self.response.out.write(json.dumps({'dans': num_dans}))
+
+
+def main():
+ application = webapp.WSGIApplication([('/', MainPage), ('/howmany', HowMany)], debug=True)
+ util.run_wsgi_app(application)
+
+
+if __name__ == '__main__':
+ main()

0 comments on commit b8a4b41

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