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(self, bbs_key): SetUtf8.set() bbs_key_original = bbs_key # キャッシュに存在するか判定 result = memcache.get("feed_" + bbs_key_original) # result=None if not result: # キャッシュに存在しない場合はRSS作成 # 掲示板取得 bbs_key = MappingId.mapping(bbs_key) bbs = None try: bbs = db.get(bbs_key) except: bbs = None if bbs == None: self.error(404) return # feedを作成 result = RssFeed.generate_feed(bbs, bbs_key) # キャッシュに入れる memcache.set("feed_" + bbs_key_original, result, 60 * 60 * 3) # 3時間 self.response.headers["Content-Type"] = "text/xml; charset=utf-8" self.response.out.write(result)
def add_support_forum(main,app): if(not app.support_forum and app.is_public): thread=MesThread() bbs_key=MappingId.mapping(BbsConst.APP_SUPPORT_BBS_ID) if(bbs_key==""): #return False main.response.out.write(Alert.alert_msg("サポートフォーラムBBS[ID:"+BbsConst.APP_SUPPORT_BBS_ID+"]が見つかりません。",main.request.host)) return True bbs=db.get(bbs_key) thread.bbs_key=bbs thread.title=app.app_name thread.author=app.author thread.summary=app.app_name+"のサポートフォーラムです。" thread.user_id=app.user_id thread.illust_mode=BbsConst.ILLUSTMODE_NONE thread.create_date=datetime.datetime.today() thread.comment_cnt=0 thread.date=datetime.datetime.today() thread.put() app.support_forum=thread app.put() #if(not app.support_forum.score): # app.support_forum.score = None # app.support_forum.put() return False
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 get(self): user = users.get_current_user() user_name=ShowEntry.get_user_name(user) bbs_list=[] if(user): user_id=user.user_id() bookmark_bbs_list=ApiBookmark.bookmark_get_bbs_list(self,user_id) rental_bbs_list=ApiUser.user_get_bbs_list(self,user_id) if(rental_bbs_list): bbs_list.extend(rental_bbs_list) if(bookmark_bbs_list): bbs_list.extend(bookmark_bbs_list) sample_bbs={ "title":"サンプルお絵描き掲示板", "key":MappingId.mapping("sample") } bbs_list.append(sample_bbs) temp_key=self.request.get("temp_key") args=None if(temp_key): temp=db.get(temp_key) if(temp.args): args=temp.args target_bbs=self.get_target_bbs(args); if(target_bbs): bbs_list=target_bbs template_values={ 'host':"./", 'is_iphone':CssDesign.is_iphone(self), 'is_tablet':CssDesign.is_tablet(self), 'is_english':CssDesign.is_english(self), 'temp_key':temp_key, 'redirect_url':self.request.path+"?temp_key="+temp_key, 'user':user, 'bbs_list':bbs_list, 'args':args, 'user_name':user_name } render=template_select.render("/html/upload_temp.html", template_values) self.response.out.write(render)
def feed_get_thread_list(req,order,offset,limit): #最大取得数 if(limit>100): limit=100 #キャッシュが有効かどうか cache_enable=ApiFeed._is_cache_enable(offset,limit,order) #キャッシュ取得 cache_id=ApiFeed._get_cache_id(order,req.request.get("bbs_id"),offset,limit) if(cache_enable): data=memcache.get(cache_id) if(data): dic=ApiObject.create_thread_object_list(req,data,req.request.get("bbs_id")) return dic #スレッド一覧取得 if(order=="hot"): rank=Ranking.get_by_key_name(BbsConst.THREAD_RANKING_KEY_NAME) if(rank==None): rank=Ranking.get_or_insert(BbsConst.THREAD_RANKING_KEY_NAME) thread_list=rank.get_rank(offset,limit) bbs_id=None else: query=ApiFeed._get_query(order,req.request.get("event_id")) bbs_id=None if(req.request.get("bbs_id")): bbs_key=MappingId.mapping(req.request.get("bbs_id")) if(bbs_key==""): return None #bbs not found query.filter("bbs_key =",db.get(bbs_key)) bbs_id=True thread_list=query.fetch(offset=offset,limit=limit) #キャッシュに乗せる if(cache_enable): memcache.set(cache_id,thread_list,BbsConst.TOPPAGE_FEED_CACHE_TIME) #リスト作成 dic=ApiObject.create_thread_object_list(req,thread_list,bbs_id) 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)