def index(request): user = None if request.session.get('token', None) is not None: client = TwitterOAuthClient(request) user = User.all().filter('token', request.session.get('token', None)).get() if user is None: return HttpResponseRedirect('/logout') # fill in missing information if user.name is None: token = user.OAuthToken() oauth_request = OAuthRequest.from_consumer_and_token(consumer, token=token, http_method='GET', http_url='https://api.twitter.com/1.1/account/verify_credentials.json') oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, token) response = client.access_resource(oauth_request) info = simplejson.loads(response) user.name = info['name'] user.timezone = info['time_zone'] user.put() # find current game game = util.get_running_game() # find players players = util.get_players(game) # find last hit last = util.get_last_hit(game) if last is not None: delta = util.timedelta2seconds(datetime.datetime.now() - last.start) timestamp = calendar.timegm(last.start.utctimetuple()) else: delta = 0 timestamp = 0 return render(request, 'index.html', {'user': user, 'players': players, 'last': last, 'delta': delta, 'timestamp': timestamp})
def status(request, username='', time=0): game = util.get_running_game() last = util.get_last_hit(game) user = last.player.user players = None response = {'modified': False} delta = util.timedelta2seconds(datetime.datetime.now() - last.start) timestamp = calendar.timegm(last.start.utctimetuple()) if username != '' and username != user.username: players = util.get_players(game) template = loader.get_template('players.html') context = Context({'players': players}) response['html'] = template.render(context) response['modified'] = True elif long(time, 10) != timestamp: response['modified'] = True if response['modified']: response.update({'user': {'link': 'http://twitter.com/%s' % user.username, 'name': user.name, 'username': '******' % user.username}, 'delta': delta, 'timestamp': timestamp}) return HttpResponse(simplejson.dumps(response), mimetype='application/json')