def get(self): gl=Global.query(Global.name=="global").fetch() stream_list = [] count_list = [] if len(gl)>0: gl=gl[0] #streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.views).fetch(3) counts=CountViews.query().order(-CountViews.numbers).fetch(3) for count in counts: stream=Stream.query(Stream.name==count.name).fetch() if (len(stream)>0): stream = stream[0] stream_list.append(stream) count_list.append(count.numbers) gl=Global.query(Global.name=="global").fetch() str = "" if(len(gl)>0): gl=gl[0] fre=gl.limit if fre==0: str="No reports" if fre==1: str="Every 5 Minutes" if fre==12: str="Every 1 hour" if fre==288: str="Every day" user_name = users.get_current_user().nickname() print count_list print stream_list template_values = { 'user_name':user_name, 'str':str, 'count_list':count_list, 'stream_list': stream_list } template = JINJA_ENVIRONMENT.get_template('trending_index.html') self.response.write(template.render(template_values))
def get(self): self.response.write(TRENDING_TEMPLATE) gl=Global.query(Global.name=="global").fetch() if(len(gl)>0): gl=gl[0] #streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.views).fetch(3) counts=CountViews.query().order(-CountViews.numbers).fetch(3) self.response.write('<table style = "width:70%">') for count in counts: stream=Stream.query(Stream.name==count.name).fetch() if (len(stream)>0): stream = stream[0] self.response.out.write('<td><div style = "position:relative;"><a href="%s"><img src="%s" ></img><div style = "position: absolute; left:0px; top:0px">%s</div></a></div><div>%s views in the past hour</div></td>' % (stream.url,stream.coverurl,stream.name,count.numbers)) self.response.write('</table>') self.response.write('<form action="/update" method="post">') self.response.write('<input type="radio" name="frequency" value="no">No reports<br>') self.response.write('<input type="radio" name="frequency" value="5m">Every 5 minutes<br>') self.response.write('<input type="radio" name="frequency" value="1h">Every 1 hour<br>') self.response.write('<input type="radio" name="frequency" value="1d">Every day<br>') self.response.write('<input type="submit" value="Update rate"></form>') gl=Global.query(Global.name=="global").fetch() if(len(gl)>0): gl=gl[0] fre=gl.limit if fre==0: str="No reports" if fre==1: str="Every 5 Minutes" if fre==12: str="Every 1 hour" if fre==288: str="Every day" self.response.write("Current Update Frequency: "+ str)
def post(self): original_url=self.request.headers['Referer'] frequency=self.request.get("frequency") gl=Global.query(Global.name=="global").fetch() #self.response.write(gl) if len(gl)<=0: gl=Global(name="global",count=0,limit=0) else: gl=gl[0] self.response.write(frequency) if frequency=="no": gl.limit=0 if frequency=="5m": gl.limit=1 # in times of increasement of cron schedule if frequency=="1h": gl.limit=12 if frequency=="1d": gl.limit=288 #self.response.write(gl) gl.put() self.redirect(original_url)
def get(self): #if users.get_current_user(): gl=Global.query(Global.name=="global").fetch() #self.response.write(gl) # test if(len(gl)>0): gl=gl[0] gl.count=gl.count+1 #self.response.write(gl.count) # test if(gl.count==gl.limit): #Change!# instead of == gl.count=0 # if users.get_current_user(): default_context = "Stream Trending Updated\n\n" emailSubject = "Stream Trending" emailSender = "*****@*****.**" mail.send_mail(sender = emailSender, to = emailSender, subject = emailSubject, body = default_context) mail.send_mail(sender = emailSender, to = "*****@*****.**", subject = emailSubject, body = default_context) mail.send_mail(sender = emailSender, to = "*****@*****.**", subject = emailSubject, body = default_context) gl.put()