# vim:fileencoding=utf8 """ Copyright © 2011 Pádraig Brady
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import cgi import datetime import re import wsgiref.handlers #from google.appengine.api import users from google.appengine.api import mail from google.appengine.api import memcache from google.appengine.ext import webapp from google.appengine.ext import db class Comment(db.Model): user = db.UserProperty() author = db.StringProperty() url = db.StringProperty() page = db.StringProperty(required=True) content = db.TextProperty() date = db.DateTimeProperty(auto_now_add=True) def previous_year_month_day(): last_year = datetime.datetime.now() - datetime.timedelta(days=1*365) return last_year.strftime("%Y-%m-%d") def age(date): age = datetime.datetime.now() - date if age.days: return date.strftime("%d %b %Y") elif not age.seconds: return "just now" else: hours = age.seconds/3600 if hours: return "%s hours ago" % hours mins = age.seconds/60 if mins: return "%s minutes ago" % mins return "%s seconds ago" % age.seconds def getcache(key, compute, time=600): value = memcache.get(key) if value is None: value = compute() memcache.set(key, value, time=time) return value class MainPage(webapp.RequestHandler): def get(self): mode = self.request.get('mode') if mode != "count": self.response.out.write("""
""") if mode == "count": value = memcache.get(self.request.path) if value is not None: self.response.out.write('%d' % value) return # Caveat is anchor '#' is not sent to server (in self.request.url) # so any links on web before Aug 7 2021 referencing specific comments, wont work # All anchors now specify the "all" parameter so will be valid going forward. if mode == "count" or self.request.get("all"): limit = "" else: self.response.out.write('load older comments\n