google app engine - time counter python GAE -
i trying number of seconds betwen when query has been launched, , when refresh page. i'm using following code:
import time last_queried = 0 def top_blogs(update = false): blogs = memcache.get(key) global last_queried if update: blogs = gqlquery("select * blog order created desc limit 10") last_queried = time.time() memcache.set(key, blogs) return blogs
when display page:
class frontpagehandler(handler): def get(self): global last_queried blogs = top_blogs() render_time=time.time() time_lapse = render_time - last_queried self.render("front.html", blogs = blogs, time=time_lapse)
it seems i'm getting in time_lapse, not difference in seconds time since epoch, doing wrong?
regards
edit: clarification purposes, here when call top_blogs function, should update query , variable last_queried in theory:
class newposthandler(handler): def post(self): subject = self.request.get("subject") content = self.request.get("content") if subject , content: = blog(parent = blog_key(), subject=subject, content=content) a.put() top_blogs(true) self.redirect("/blog/%s" %str(a.key().id()))
bear in mind when importing in python don't use capital letters.
you can try following example , see get:
from datetime import datetime last_queried = datetime.now() render_time = datetime.now() time_lapse = last_queried - render_time time_lapse.seconds() # -> number time_lapse.microseconds()
Comments
Post a Comment