-
-
Save nomolosvulgaris/4663974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Girls gone wild!</title> | |
<link rel="stylesheet" type="text/css" href="/static/style.css"> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
<script type="text/javascript" src="http://localhost:8080/application.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
var jug = new Juggernaut; | |
jug.subscribe('babes', function (data) { | |
changeValue(data); | |
}); | |
$('li').each(function(i) { | |
$(this).click(function() { | |
$.ajax({ | |
url: '/vote/' + i, | |
method: 'POST', | |
success: function (data) { | |
changeValue(data) | |
} | |
}) | |
}) | |
}); | |
}); | |
function changeValue(data) { | |
$('.votescounter').eq(data.babe).text(data.result); | |
}; | |
</script> | |
</head> | |
<body> | |
<ul> | |
<li><img src="/static/babes/1.jpeg"/><span class="votescounter"></span></li> | |
<li><img src="/static/babes/2.jpeg"/><span class="votescounter"></span></li> | |
<li><img src="/static/babes/3.jpeg"/><span class="votescounter"></span></li> | |
<li><img src="/static/babes/4.jpeg"/><span class="votescounter"></span></li> | |
<li><img src="/static/babes/5.jpeg"/><span class="votescounter"></span></li> | |
</ul> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, redirect, jsonify | |
from juggernaut import Juggernaut | |
from redis import Redis | |
app = Flask(__name__) | |
app.debug = True | |
db = Redis() | |
jug = Juggernaut() | |
@app.route('/') | |
def hello(): | |
return redirect('/static/index.html') | |
@app.route('/vote/<int:voteid>', methods=['POST']) | |
def vote(voteid): | |
if voteid < 0 or voteid > 4: | |
return jsonify({'error': 'strange vote?!'}) | |
res = db.incr('babes:vote:' + str(voteid)) | |
result = {'result': res, 'babe': voteid} | |
jug.publish('babes', result) | |
return jsonify(result) | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: #f0f0f0; | |
} | |
ul { | |
list-style-type: none; | |
} | |
.votescounter { | |
font-size: 200px; | |
margin-left: 100px; | |
color: #505050; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment