def mapping(bbs,thread_key): #直値 if(len(thread_key)>20): return ApiObject.get_cached_object(thread_key) #キャッシュヒット判定 bbs_key=str(bbs.key()) mapped_key=memcache.get(BbsConst.OBJECT_THREAD_ID_MAPPING_HEADER+"_"+bbs_key+"_"+thread_key) if mapped_key is not None: return ApiObject.get_cached_object(mapped_key) #探索 query=db.Query(MesThread,keys_only=True) query.filter("bbs_key =",bbs) query.filter("short =",thread_key) thread=None try: thread=query[0] thread=ApiObject.get_cached_object(thread) except: thread=None #キャッシュに登録 if thread and thread.short: new_key=str(thread.key()) memcache.set(BbsConst.OBJECT_THREAD_ID_MAPPING_HEADER+"_"+bbs_key+"_"+thread.short,new_key,BbsConst.OBJECT_MAPPING_CACHE_TIME) #image_keyを取得しておく if thread and thread.image_key: thread.cached_image_key=str(thread.image_key.key()) #スレッドを返す return thread
def get_thread_list(self,analytics): start_date=str(datetime.date.today()+datetime.timedelta(days=-1)) end_date=str(datetime.date.today()) result=analytics.get("page",".*",start_date,end_date) thread_list=[] for one in result: url=one["ga:pagePath"] count=int(one["ga:pageviews"]) data=url.split("/") try: bbs_name=str(data[1]) thread_name=str(data[2].split(".")[0]) except: continue bbs_key=MappingId.mapping(bbs_name) bbs=ApiObject.get_cached_object(bbs_key) if(not bbs): continue thread = MappingThreadId.mapping(bbs,thread_name) if(not thread): continue while(count>=1): thread_list.append(thread.key()) count=count-1 return thread_list
def get_bbs(req,bbs_key): bbs_key=MappingId.mapping(bbs_key) if(bbs_key==""): Alert.alert_msg_notfound(req) return None bbs=ApiObject.get_cached_object(bbs_key) if(bbs == None): Alert.alert_msg_notfound(req) return None return bbs
def post(self): #BBS取得 bbs_key=self.request.get("bbs") bbs=None if(bbs_key): bbs=ApiObject.get_cached_object(str(bbs_key)) if(not bbs): return #カウンタを更新 counter=bbs.counter counter.update_counter()
def bookmark_get_thread_user_list(req): thread_key=req.request.get("thread_key") bookmark_list=Bookmark.all().filter("thread_key_list =",db.Key(thread_key)).fetch(limit=100) #comment comment={} thread=ApiObject.get_cached_object(db.Key(thread_key)) if(not thread): return [] if(thread.bookmark_comment): comment=pickle.loads(thread.bookmark_comment) #user list dic=[] for bookmark in bookmark_list: one_dic=ApiObject.create_user_object(req,bookmark) user_id=None if(one_dic.has_key("user_id")): user_id=one_dic["user_id"] if(user_id and comment.has_key(user_id)): one_dic["comment"]=comment[user_id] dic.append(one_dic) return dic
def get(self,bbs_key,thread_key): SetUtf8.set() #ホストチェック if SpamCheck.is_deny(self.request): self.response.set_status(401) return #英語版かどうか is_english=CssDesign.is_english(self) #BBSを取得 bbs_key=MappingId.mapping(bbs_key) bbs=ApiObject.get_cached_object(bbs_key) if(bbs == None): Alert.alert_msg_notfound(self) return #BBSが削除されていた場合 if(bbs.del_flag) : if(is_english): Alert.alert_msg_with_write(self,"This bbs was deleted.") else: Alert.alert_msg_with_write(self,"このBBSは削除されました。") return #ページ番号を取得 col_num = 10 page = 1 if self.request.get("page"): page = int(self.request.get("page")) if page < 1: page=1 #メンテナンス画面 is_maintenance=0 if(MaintenanceCheck.is_appengine_maintenance()): is_maintenance=1 #オーダー取得 order="update" if(bbs.default_comment_order==1): order="new" if self.request.get("order"): order=self.request.get("order") #スレッド取得 thread=ShowThread.get_thread(bbs,thread_key) if(thread == None): Alert.alert_msg_notfound(self) return #コメント数を更新 if(bbs.page_comment_n): col_num=bbs.page_comment_n if(self.request.get("limit")): col_num=int(self.request.get("limit")) #コメントの一覧を取得 query=ShowThread.get_comment_query(thread,order) entry_num = query.count() if(entry_num==0): com_list_ = [] else: com_list_ = query.fetch(limit=col_num, offset=(page-1)*col_num) #検索 search="" if(self.request.get("search")): search=self.request.get("search") query=""+search+' thread_key:"'+str(thread.key())+'"' com_list_=SearchThread.search(query,page,col_num,BbsConst.SEARCH_ENTRY_INDEX_NAME) #実体への変換 com_list_=ApiObject.get_cached_object_list(com_list_) #現在のスレッドへのURLを取得 host_url=MappingId.mapping_host_with_scheme(self.request)+"/" #編集モードか user = users.get_current_user() edit_flag = 0 if(not OwnerCheck.check(bbs,user)): edit_flag = 1 logined=0 if(user): logined=1 owner=user if(OwnerCheck.check(bbs,user)): owner=None admin_user=OwnerCheck.is_admin(user) #ページリンクを作成 page_url_base = MappingId.get_usr_url(host_url,bbs)+thread_key+'.html?page=' page_list=ShowThread.create_page_list(page,entry_num,col_num) #掲示板のデザインを取得 design=CssDesign.get_design_object(self,bbs,host_url,1) #コメントフォームを取得する show_comment_form=1 if(bbs.comment_login_require and not(owner)): show_comment_form=0 #名前取得 user_name=ShowEntry.get_user_name(user) #自分のイラストか my_illust=False if(user and thread.user_id==user.user_id()): my_illust=True #IPを表示するかどうか show_ip=False if(self.request.get("show_ip") and (owner or admin_user)): show_ip=True #コメントのレンダリング comment=ShowEntry.render_comment(self,host_url,bbs,thread,com_list_,edit_flag,bbs_key,logined,show_comment_form,admin_user,user_name,user,show_ip) #凍結されているか frozen=ApiObject.is_frozen_thread(thread) #拍手が有効かどうか applause_enable=not (user and thread.user_id and thread.user_id==user.user_id()) #メッセージ message=memcache.get(BbsConst.OBJECT_THREAD_MESSAGE_HEADER+str(thread.key())) #関連イラスト related=self._get_related(bbs,thread,design["is_iphone"],design["is_tablet"]) #スパム対策 force_login_to_create_new_image=BbsConst.FORCE_LOGIN_TO_CREATE_NEW_IMAGE force_login_to_create_new_comment=BbsConst.FORCE_LOGIN_TO_CREATE_NEW_COMMENT #描画 template_values = { 'host': host_url, 'usrhost': MappingId.get_usr_url(host_url,bbs), 'bbs': bbs, 'bbs_str_key': str(bbs.key()), 'thread': thread, 'edit_flag':edit_flag, 'url': 'edit', 'url_linktext': 'edit blogs', 'bbs_key': bbs_key, 'page':page, 'page_url_base':page_url_base, 'page_list':page_list, 'logined':logined, 'user':user, 'owner':owner, 'my_illust':my_illust, 'template_path':design["template_path"], 'css_name':design["css_name"], 'is_iphone':design["is_iphone"], 'is_tablet':design["is_tablet"], 'template_base_color':design["template_base_color"], 'admin_user':admin_user, 'order':order, 'is_maintenance':is_maintenance, 'redirect_url': self.request.path, 'comment':comment, 'show_comment_form':show_comment_form, 'user_name':user_name, 'search': search, 'limit': col_num, 'frozen': frozen, 'applause_enable': applause_enable, 'message': message, 'is_english': is_english, 'related': related, 'show_ip': show_ip, 'force_login_to_create_new_image': force_login_to_create_new_image, 'force_login_to_create_new_comment': force_login_to_create_new_comment } path = "/html/"+design["base_name"] self.response.out.write(template_select.render(path, template_values)) CounterWorker.update_counter(self,bbs,thread,owner)
def _create_ranking_core(self,thread_list): #ハッシュにthread_keyを入れていく rank={} first_ranking_list=[] for thread in thread_list: if(rank.has_key(thread)): rank[thread]=rank[thread]+1 else: rank[thread]=1 first_ranking_list.append(thread) #1次ランキングに出現したもののスコア補正 rank_bbs={} rank_user={} for k in first_ranking_list: #スレッドの実体を取得 thread=ApiObject.get_cached_object(k) #イラストモードだけ if(not thread or thread.illust_mode!=BbsConst.ILLUSTMODE_ILLUST): rank[k]=0 continue #BBSランクを加算(純粋PV) if(thread): bbs=thread.cached_bbs_key bbs_main=ApiObject.get_cached_object(bbs) if(not(bbs_main and bbs_main.disable_news)): if(not rank_bbs.has_key(bbs)): rank_bbs[bbs]=0 rank_bbs[bbs]=rank_bbs[bbs]+rank[k] #USERランクを加算(純粋PV) if(thread): user_id=thread.user_id if(user_id): if(not rank_user.has_key(user_id)): rank_user[user_id]=0 rank_user[user_id]=rank_user[user_id]+rank[k] #経過日数と付加情報で補正 day_left=(self.get_sec(datetime.datetime.now())-self.get_sec(thread.create_date))*1.0/60/60/24 score=0 if(thread.bookmark_count): score=score+thread.bookmark_count*5 if(thread.applause): score=score+thread.applause rank[k]=(rank[k]+score)/(day_left+1) #非表示スレッドのランクを落とす if(thread and bbs_main and bbs_main.disable_news): rank[k]=0 #スレッドランキング作成 self.ranking_list=[] for k, v in sorted(rank.items(), key=lambda x:x[1], reverse=True): self.ranking_list.append(k) if(len(self.ranking_list)>=BbsConst.THREAD_RANKING_MAX): break #BBSランキング作成 self.bbs_ranking_list=[] for k, v in sorted(rank_bbs.items(), key=lambda x:x[1], reverse=True): self.bbs_ranking_list.append(k) if(len(self.bbs_ranking_list)>=BbsConst.BBS_RANKING_MAX): break #USERランキング作成 self.user_id_ranking_list=[] for k, v in sorted(rank_user.items(), key=lambda x:x[1], reverse=True): self.user_id_ranking_list.append(k) if(len(self.user_id_ranking_list)>=BbsConst.USER_RANKING_MAX): break