Instantly share code, notes, and snippets.

@yne /ipbook.py
Created Mar 12, 2017

Embed
What would you like to do?
Google AppEngine most recent visitor page
#!/usr/bin/env python
from flask import Flask
from flask import request
from datetime import datetime
app = Flask(__name__)
#app.config['DEBUG'] = True
from google.appengine.ext import ndb
class Client(ndb.Model):
addr = ndb.StringProperty(indexed=True)
date = ndb.DateTimeProperty(auto_now=True)
@app.route('/boot.ini')
def hello():
Client.get_or_insert(request.remote_addr, addr=request.remote_addr).put()
clients=Client.query().order(-Client.date).fetch(100)
return "\n".join(map(lambda c:"%s %i"%(c.addr, (datetime.now()-c.date).total_seconds()), clients)), 200, {'Content-Type': 'text/plain'}
@app.route('/flush')
def flush():
return "%r"%ndb.delete_multi(Client.query().fetch(keys_only=True))
@app.errorhandler(404)
def page_not_found(e):
return 'Sorry, nothing at this URL.', 404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment