コード例 #1
0
	def update_url(self,url):
		#ID取得
		id=""
		m = re.search(r"http://www.nicovideo.jp/watch/([a-z0-9]*)", url)
		if(m):
			id=m.group(1)
		else:
			return None

		#サーチ
		query=NicoTrackerRec.all().filter("id = ",id)
		if(query.count()==0):
			rec=NicoTrackerRec()
		else:
			rec=query[0]
		
		#初期設定
		rec.url=url
		rec.id=id
		rec.title=""
		
		return self.update_core(rec,False,False)
コード例 #2
0
	def auto_update(self):
		query=NicoTrackerRec().all()#db.Query(NicoTrackerRec,keys_only=True)
		query=query.order("date")	#古い順
		update_unit=100	#out of timeにならない範囲で取得
						#100*24times=2400件が毎日更新できるリミット

		rec_list=query.fetch(limit=update_unit)
		#rec_list=db.get(rec_list)

		cnt=0
		update_cnt=0
		update_list=[]
		for rec in rec_list:
			#get and update
			rec=self.update_core(rec,False,True)
			if(rec and rec.updated):
				update_cnt=update_cnt+1
				update_list.append(rec)
			#rec=None #release memory

			#next
			if(len(update_list)>=20):
				db.put(update_list)
				update_list=[]	#release memory

			cnt=cnt+1
			#if(cnt%100==0):
			#	logging.info("update nico_tracker "+str(cnt))

		if(len(update_list)>=1):
			db.put(update_list)
			update_list=[]

		#if(update_cnt):
		#	db.put(rec_list)

		logging.info("updated "+str(update_cnt)+" of "+str(cnt))

		gc.collect()
コード例 #3
0
	def get(self):
		SetUtf8.set()
		
		#ブックマーク制御
		user = users.get_current_user()
		bookmark=NicoTracker.get_bookmark(user)
		if(self.request.get("add_bookmark")):
			NicoTracker.add_bookmark(bookmark,self.request.get("id"),self.request.get("title"))
		if(self.request.get("del_bookmark")):
			NicoTracker.del_bookmark(bookmark,self.request.get("id"))
		url_log = users.create_logout_url(self.request.uri)
		if(not user):
			url_log = users.create_login_url(self.request.uri)
			
		url = ""#http://www.nicovideo.jp/watch/sm15521745"
		if(self.request.get("url")):
			url=self.request.get("url")
		
		if(url==""):
			rec=None
		else:
			if(url=="update_all"):
				rec=self.auto_update()
			else:
				rec=self.update_url(url)
		
		play_cnt_graph=""
		comment_cnt_graph=""
		list_tbl=""
		if(rec):
			#GRAPH
			play_cnt_graph=NicoTracker.create_graph(rec.day_list,rec.play_cnt_list);
			comment_cnt_graph=NicoTracker.create_graph(rec.day_list,rec.comment_cnt_list);
			
			#TABLE
			no=0
			for day in rec.day_list:
				list_tbl+="<TR><TD>"+day+"</TD>"
				list_tbl+="<TD>"+rec.play_cnt_list[no]+"</TD>"
				list_tbl+="<TD>"+rec.comment_cnt_list[no]+"</TD></TR>\n"
				no=no+1
		
		query=NicoTrackerRec.all()
		rec_cnt=query.count(limit=100000)
		rec_list=query.order("-play_cnt_now").fetch(limit=10)
		
		query=NicoTrackerBookmark.all()
		book_cnt=query.count()
		
		bookmark_list=[]
		if(bookmark):
			for i in range(0,len(bookmark.bookmark_id_list)):
				playcnt=0
				try:
					playcnt=NicoTrackerRec.all().filter("id =",bookmark.bookmark_id_list[i])[0].play_cnt_now
				except:
					playcnt=0
				if(playcnt==None):
					playcnt=0
				url_base="http://www.nicovideo.jp/watch/"
				
				#del_button="<div class='delete_button' onClick='click_delete(\""
				del_button="<img src='static_files/nicotra/book.gif' onClick='click_delete(\""
				del_button+=bookmark.bookmark_id_list[i]
				del_button+="\",\""+url+"\");'>";
				#del_button+="del</div>";
				
				title=bookmark.bookmark_title_list[i].split(" ‐ ")[0]
				#if(len(title)>=30):
				#	title=title[0:30]+"…"
				
				bookmark_list.append(del_button+"<A HREF='nico_tracker?url="+url_base+bookmark.bookmark_id_list[i]+"'>"+title+"</A> "+str(playcnt)+"[play] ");
		
		is_anim_icon=self.request.get("is_anim_icon")
		
		host_url =self.request.host
		template_values = {
			'host': host_url,
			'rec': rec,
			'rec_list': rec_list,
			'url': url,
			'play_cnt_graph': play_cnt_graph,
			'comment_cnt_graph': comment_cnt_graph,
			'list_tbl': list_tbl,
			'rec_cnt': rec_cnt,
			'user': user,
			'bookmark_list': bookmark_list,
			'url_log': url_log,
			'is_anim_icon': is_anim_icon,
			'book_cnt': book_cnt
			}
		
		path = '/html/nico_tracker/nico_tracker.html'
		render=template_select.render(path, template_values)
		self.response.out.write(render)