diff options
-rw-r--r-- | app.yaml | 13 | ||||
-rw-r--r-- | favicon.ico | bin | 0 -> 1406 bytes | |||
-rw-r--r-- | framed.py | 50 | ||||
-rw-r--r-- | mainpage.html | 109 |
4 files changed, 159 insertions, 13 deletions
@@ -4,6 +4,17 @@ runtime: python api_version: 1 handlers: -- url: /.* +- url: /favicon.ico + static_files: favicon.ico + upload: favicon.ico + +- url: / + static_files: mainpage.html + upload: mainpage.html + +- url: /loadnewtitles + login: admin script: framed.py +- url: /.* + script: framed.py
\ No newline at end of file diff --git a/favicon.ico b/favicon.ico Binary files differnew file mode 100644 index 0000000..928dc53 --- /dev/null +++ b/favicon.ico @@ -8,27 +8,52 @@ import re from time import sleep from random import randint +class Title(db.Model): + title = db.StringProperty(required=True) + code = db.StringProperty(required=True) + actors = db.StringListProperty() + characters = db.StringListProperty() + lastThumb = db.IntegerProperty() +class Answer(db.Model): + title = db.ReferenceProperty(Title) + answer = db.ListProperty(int) + class NewQuestion(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'application/json' titles = Title.all() title = titles[randint(0, titles.count() - 1)] - if len(title.actors) == 0: - return self.get() - - url = "http://img.anyclip.com/thumbnails/%s/tmb_%s_480.jpg" % (title.code, "910") #frame hard-coded for now + url = "http://img.anyclip.com/thumbnails/%s/tmb_%s_480.jpg" % (title.code, randint(1, title.lastThumb / 10) * 10) #frame hard-coded for now cast = "" for i in range(len(title.actors)): if i != 0: cast += "," cast += "[\"%s\",\"%s\"]" % (title.actors[i], title.characters[i]) - self.response.out.write("{title:\"%s\",frame:\"%s\",cast:[%s]}" % (title.title, url, cast)) -class Title(db.Model): - title = db.StringProperty(required=True) - code = db.StringProperty(required=True) - actors = db.StringListProperty() - characters = db.StringListProperty() - lastThumb = db.IntegerProperty() + self.response.out.write("{\"title\":\"%s\",\"code\":\"%s\",\"frame\":\"%s\",\"cast\":[%s]}" % (title.title, title.code, url, cast)) + +class AnswerQuestion(webapp.RequestHandler): + def get(self): + code = self.request.get("code") + answer = self.request.get("inframe") + if code == "" or answer == "": + return + answers = answer.split(",") + for i in range(len(answers)): + try: + answers[i] = int(answers[i]) + if (answers[i] > 9): + return + except: + return + titleQuery = Title.all().filter('code = ', code).fetch(1) + if len(titleQuery) != 1 or len(answers) == 0 or (answers[i] == -1 and len(answers) > 1): + return + answer = Answer() + answer.title = titleQuery[0] + answer.answer = answers; + answer.put() + self.response.out.write(str(answers) + "<br>" + code); + class LoadNewTitles(webapp.RequestHandler): def __init__(self): self.api = AnyClipAPI("CAD58B9E-F045-492F-81B9-22CFE6B00604") @@ -90,7 +115,8 @@ class LoadNewTitles(webapp.RequestHandler): application = webapp.WSGIApplication( [('/newquestion', NewQuestion), - ('/loadnewtitles', LoadNewTitles)], + ('/loadnewtitles', LoadNewTitles), + ('/answerquestion', AnswerQuestion)], debug=True) def main(): diff --git a/mainpage.html b/mainpage.html new file mode 100644 index 0000000..d198ed4 --- /dev/null +++ b/mainpage.html @@ -0,0 +1,109 @@ +<html> +<head> +<title>Framed</title> +<script language="JavaScript"> +var requestObj = null; +var answerObj = null; +var questions = new Array(); +var hasLoadedFirst; +var thumbnail = null; +var title = null; +var optionBox = null; +var currentQuestion = null; + +function fillQuestionQueue() { + requestObj.open("GET", "/newquestion"); + requestObj.onreadystatechange = function() { + if (requestObj.readyState != 4) + return; + if (requestObj.responseText == "") { + fillQuestionQueue(); + return; + } + var question = eval("(" + requestObj.responseText + ")"); + var preloadImage = new Image(); + preloadImage.src = question.frame; + question.frame = preloadImage; + questions.push(question); + if (!hasLoadedFirst) { + showNextQuestion(); + hasLoadedFirst = true; + } + if (questions.length < 5) + fillQuestionQueue(); + }; + requestObj.send(null); +} + +function showNextQuestion() { + if (questions.length == 0) { + hasLoadedFirst = false; + fillQuestionQueue(); + return; + } + currentQuestion = questions.shift(); + thumbnail.src = currentQuestion.frame.src; + title.innerHTML = currentQuestion.title; + var checkBoxes = ""; + for (var i = 0; i < currentQuestion.cast.length; i++) { + checkBoxes += "<label><input type=\"checkbox\" id=\"cast" + i.toString() + "\" \\>"+ currentQuestion.cast[i][0] + " as " + currentQuestion.cast[i][1] + "</label><br \\>"; + } + optionBox.innerHTML = checkBoxes; + fillQuestionQueue(); +} + +function answerQuestion() { + var castInFrame = new Array(); + for (var i = 0; i < currentQuestion.cast.length; i++) { + if (document.getElementById("cast" + i.toString()).checked) + castInFrame.push(i); + } + if (castInFrame.length == 0) { + alert("Please select the characters in the frame. If you do not know, press skip. If there are none, press none."); + return; + } + answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&inframe=" + castInFrame.toString()); + answerObj.send(null); + showNextQuestion(); +} +function emptyAnswer() { + answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&inframe=-1"); + answerObj.send(null); + showNextQuestion(); +} + +function init() { + if (navigator.appName == "Microsoft Internet Explorer") + answerObj = requestObj = new ActiveXObject("Microsoft.XMLHTTP"); + else + answerObj = requestObj = new XMLHttpRequest(); + thumbnail = document.getElementById("thumbnail"); + title = document.getElementById("title"); + optionBox = document.getElementById("options"); + hasLoadedFirst = false; + fillQuestionQueue(); +} + +</script> +</head> +<body onLoad="init();"> +<h1>Framed <i>by AnyClip</i></h1> +<table> +<tr> +<td valign="top" width="500"> +<div id="title" style="font-size:14pt;font-weight:bold;"></div> +<img width="480" id="thumbnail" /> +</td> +<td valign="top" width="300"> +<div id="options"> +</div> +</td> +<td valign="top" width="200"> +<button onClick="answerQuestion()"><h2>Answer & Next</h2></button><br /> +<button onClick="emptyAnswer()">None of the Above</button><br /> +<button onClick="showNextQuestion()">Skip Question</button><br /> +</td> +</tr> +</table> +</body> +</html>
\ No newline at end of file |