def get(self, typ, vid): video = Video.all().filter('typ =', typ).filter('vid =', vid).get() if not video: video = Video(typ=typ, vid=vid) if video: video.put() else: self.error(404) cmts = memcache.get(str(video.key().id_or_name())) if not cmts: cmts = video.comment_set memcache.set(str(video.key().id_or_name()), cmts) tmpvars = {'comments': cmts} self.render('comment.xml', tmpvars)
def get(self,typ,vid): video = Video.all().filter('typ =',typ).filter('vid =',vid).get() if not video: video = Video(typ = typ, vid = vid) if video: video.put() else: self.error(404) cmts = memcache.get(str(video.key().id_or_name())) if not cmts: cmts = video.comment_set memcache.set(str(video.key().id_or_name()),cmts) tmpvars = {'comments':cmts} self.render('comment.xml',tmpvars)
def post(self, typ, vid): now = datetime.now() + timedelta(hours=+8) #date check date = self.request.get('date') try: date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S') postdelta = abs(now - date) except: #拒绝不合法的时间格式 self.response.out.write('busy,code:1') return #self.response.out.write(str(abs(postdelta.seconds))+'\r\n')#不能给用户看到 if DELAYCHECK and (postdelta.days != 0 or postdelta.seconds > DELAYMAX ): #时间有效性检验,如果与服务器间隔大于60s,就为非法 self.response.out.write('busy,code:2') return #post interval limitation ipstr = self.request.remote_addr ip = Ip.all().filter('ip =', ipstr).get() if ip: delta = now - ip.lastpostdate if delta.days == 0 and abs(delta.seconds) < POSTINTERVAL: self.response.out.write('busy,code:3') return else: ip.lastpostdate = now ip.put() else: ip = Ip(ip=ipstr, lastpostdate=now) ip.put() video = Video.all().filter('typ =', typ).filter('vid =', vid).get() if not video: video = Video(typ=typ, vid=vid) if video: video.put() else: self.error(404) text = unicode(self.request.get('message')).strip() stime = float(self.request.get('playTime')) mode = int(self.request.get('mode')) fontsize = int(self.request.get('fontsize')) color = int(self.request.get('color')) cmt = Comment(author_ip=ipstr, text=text, stime=stime, mode=mode, fontsize=fontsize, color=color, cid=video, postdate=(datetime.now() + timedelta(hours=+8))) if cmt: cmt.put() memcache.delete(str(video.key().id_or_name())) self.response.out.write('OK') else: self.response.out.write('Failed')
def post(self,typ,vid): now = datetime.now() + timedelta(hours=+8) #date check date = self.request.get('date') try: date = datetime.strptime(date,'%Y-%m-%d %H:%M:%S') postdelta = abs(now - date) except:#拒绝不合法的时间格式 self.response.out.write('busy,code:1') return #self.response.out.write(str(abs(postdelta.seconds))+'\r\n')#不能给用户看到 if DELAYCHECK and (postdelta.days != 0 or postdelta.seconds > DELAYMAX):#时间有效性检验,如果与服务器间隔大于60s,就为非法 self.response.out.write('busy,code:2') return #post interval limitation ipstr = self.request.remote_addr ip = Ip.all().filter('ip =',ipstr).get() if ip: delta = now - ip.lastpostdate if delta.days == 0 and abs(delta.seconds) < POSTINTERVAL: self.response.out.write('busy,code:3') return else: ip.lastpostdate = now ip.put() else: ip = Ip(ip=ipstr,lastpostdate = now) ip.put() video = Video.all().filter('typ =',typ).filter('vid =',vid).get() if not video: video = Video(typ = typ, vid = vid) if video: video.put() else: self.error(404) text = unicode(self.request.get('message')).strip() stime = float(self.request.get('playTime')) mode = int(self.request.get('mode')) fontsize = int(self.request.get('fontsize')) color = int(self.request.get('color')) cmt = Comment(author_ip=ipstr, text=text, stime=stime, mode=mode, fontsize=fontsize, color=color, cid=video, postdate=(datetime.now() + timedelta(hours=+8)) ) if cmt: cmt.put() memcache.delete(str(video.key().id_or_name())) self.response.out.write('OK') else: self.response.out.write('Failed')