def get(self): #日本語対応 SetUtf8.set() if(ApiObject.check_api_capacity(self)): return dic=ApiBookmark.get_core(self) ApiObject.write_json_core(self,dic)
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 post(self): SetUtf8.set() page=None if(self.request.get("page")): page=self.request.get("page") user = users.get_current_user() if(not user): if(page=="update"): dic={"status":"failed","message":"アプリを登録するにはログインする必要があります。"} ApiObject.write_json_core(self,dic) return else: self.response.out.write(Alert.alert_msg("アプリを登録するにはログインする必要があります。",self.request.host)) return if(page=="update"): dic=DevPortal.update_app(self,user) if(dic==None): return ApiObject.write_json_core(self,dic) return if(page=="submit"): if(not DevPortal.add_new_app(self,user)): return DevPortal.ret(self,"top")
def user_get_profile(req,user_id,bookmark=None): if(not bookmark): bookmark=ApiObject.get_bookmark_of_user_id(user_id) if(not bookmark): return [] one_dic=ApiObject.create_user_object(req,bookmark) one_dic["profile"]=bookmark.profile return one_dic
def bookmark_get_app_list(req,user_id): bookmark=ApiObject.get_bookmark_of_user_id(user_id) if(bookmark==None): return [] dic=[] for app_key in bookmark.app_key_list: app=db.get(app_key) one_dic=ApiObject.create_app_object(req,app) dic.append(one_dic) return dic
def user_get_home_timeline(req,user_id): #そのユーザのフォローしているユーザのタイムライン bookmark=ApiObject.get_bookmark_of_user_id(user_id) if(bookmark==None): return [] feed_key_list=ApiObject.offset_and_limit(req,bookmark.stack_feed_list) feed_list=ApiObject.get_cached_object_list(feed_key_list) dic=ApiObject.create_feed_object_list(req,feed_list,feed_key_list) return dic
def post_snapshot(self): key=self.request.get("key") snap_shot_0=self.request.get("snap_shot_0") snap_shot_1=self.request.get("snap_shot_1") thumbnail=self.request.get("thumbnail") snap_range=int(self.request.get("snap_range")) try: db.run_in_transaction(Chat.post_snapshot_core,key,snap_shot_0,snap_shot_1,snap_range,thumbnail) ApiObject.write_json_core(self,{"status":"success"}) except: ApiObject.write_json_core(self,{"status":"failed"})
def bookmark_get_thread_list(req,user_id,bookmark=None): if(not bookmark): bookmark=ApiObject.get_bookmark_of_user_id(user_id) if(bookmark==None): return [] thread_key_list=bookmark.thread_key_list thread_key_list=ApiObject.offset_and_limit(req,thread_key_list) dic=ApiObject.create_thread_object_list(req,thread_key_list,"bookmark") ApiBookmark.add_removed_thread_to_dic(req,dic,thread_key_list) return dic
def user_get_bbs_list(req,user_id): query=db.Query(Bbs,keys_only=True) query=query.filter("user_id =",user_id).order("-create_date") bbs_key_list=query.fetch(limit=1000,offset=0) dic=[] bbs_list=ApiObject.get_cached_object_list(bbs_key_list) for bbs in bbs_list: if(bbs.del_flag): continue one_dic=ApiObject.create_bbs_object(req,bbs) if(not one_dic): continue dic.append(one_dic) return dic;
def post_command(self): key=self.request.get("key") cmd_count=int(self.request.get("command_count")) user_count=int(self.request.get("user_count")) client_id=self.request.get("client_id") cmd_list="" for i in range(0,cmd_count): cmd=self.request.get("command"+str(i)) if(not cmd): cmd_list=None break cmd_list=cmd_list+cmd if(i!=cmd_count-1): cmd_list=cmd_list+" , " #if(not cmd_list): # ApiObject.write_json_core(self,{"status":"failed"}) # return try: size=db.run_in_transaction(Chat.post_command_core,key,cmd_list,cmd_count,user_count,client_id) #排他制御を行う if(size==Chat.ERROR_NO_ROOM): ApiObject.write_json_core(self,{"status":"not_found"}) else: if(size==Chat.ERROR_DISCONNECT): ApiObject.write_json_core(self,{"status":"disconnect"}) else: ApiObject.write_json_core(self,{"status":"success","size":size}) except: ApiObject.write_json_core(self,{"status":"failed"})
def render_comment_list(req, all_threads_cached, host_url, bbs, show_comment_form, logined, is_admin, user_name, user): edit_flag = False show_ip = False bbs_key = bbs.key() #コメントとレスを先行して全て取得 entry_key_list = [] for thread in all_threads_cached: if not thread: continue for entry in thread.cached_entry_key: entry_key_list.append(entry) entry_hash = ApiObject.get_cached_object_hash(entry_key_list) res_hash = ShowEntry._get_entry_res(entry_hash) #コメントをレンダリング for thread in all_threads_cached: if not thread: continue entry_list = [] for entry in thread.cached_entry_key: one_entry = entry_hash[entry] entry_list.append(one_entry) thread.cached_render_comment = ShowEntry._render_comment_core( req, host_url, bbs, thread, entry_list, edit_flag, bbs_key, logined, show_comment_form, is_admin, user_name, user, res_hash, show_ip)
def get_core(self): #パラメータ取得 method="" if(self.request.get("method")): method=self.request.get("method"); user_id="" if(self.request.get("user_id")): user_id=self.request.get("user_id") #返り値 dic={"method":method} #ユーザクラス if(method=="getUser"): dic=ApiUser.user_get_user(self,user_id) if(method=="getProfile"): dic=ApiUser.user_get_profile(self,user_id) if(method=="getFollow" or method=="getFollowFast"): dic=ApiUser.user_get_follow(self,user_id,method=="getFollowFast") if(method=="getFollower" or method=="getFollowerFast"): dic=ApiUser.user_get_follower(self,user_id,method=="getFollowerFast") if(method=="getBbsList"): dic=ApiUser.user_get_bbs_list(self,user_id) if(method=="getThreadList"): dic=ApiUser.user_get_thread_list(self,user_id) if(method=="getTimeline"): dic=ApiUser.user_get_timeline(self,user_id) if(method=="getHomeTimeline"): dic=ApiUser.user_get_home_timeline(self,user_id) return ApiObject.add_json_success_header(dic)
def get_core(self): #パラメータ取得 method="" if(self.request.get("method")): method=self.request.get("method"); user_id="" if(self.request.get("user_id")): user_id=self.request.get("user_id") #返り値 dic={"method":method} #ブックマーククラス if(method=="getThreadList"): dic=ApiBookmark.bookmark_get_thread_list(self,user_id) if(method=="getBbsList"): dic=ApiBookmark.bookmark_get_bbs_list(self,user_id) if(method=="getAppList"): dic=ApiBookmark.bookmark_get_app_list(self,user_id) if(method=="getBbsUserList"): dic=ApiBookmark.bookmark_get_bbs_user_list(self) if(method=="getThreadUserList"): dic=ApiBookmark.bookmark_get_thread_user_list(self) if(method=="getAppUserList"): dic=ApiBookmark.bookmark_get_app_user_list(self) if(dic==None): dic={"status":"failed","message":"ブックマークの取得に失敗しました。"} else: dic=ApiObject.add_json_success_header(dic) return dic
def _append_list_core(data,bookmark_key_list): #batch get try: bookmark_list=db.get(bookmark_key_list) except db.BadValueError as e: logging.error(e) bookmark_list=None #BadValueError: Property follower_list is requiredの対策 if(bookmark_list==None): bookmark_list=[] for bookmark_key in bookmark_key_list: try: bookmark_list.append(db.get(bookmark_key)) except db.BadValueError as e: logging.error(e) #update and put put_bookmark_list=[] for bookmark in bookmark_list: if(bookmark): bookmark=ApiObject.set_list_if_empty(bookmark) if(StackFeed._append_one_core(data,bookmark)): put_bookmark_list.append(bookmark) #batch put if(len(put_bookmark_list)>=1): db.put(put_bookmark_list) put_bookmark_list=[]
def _get_related(bbs,thread,is_iphone,is_tablet): related_illust_cnt=6 try: thread_query=ShowThread._get_related_query(bbs,thread) thread_query.filter('create_date > ',thread.create_date) thread_query.order('create_date') thread_after=thread_query.fetch(limit=related_illust_cnt) except: thread_after=[] try: thread_query=ShowThread._get_related_query(bbs,thread) thread_query.filter('create_date < ',thread.create_date) thread_query.order('-create_date') thread_before=thread_query.fetch(limit=related_illust_cnt*2-len(thread_after)) except: thread_before=[] all_threads=[] if(thread_after): thread_after.reverse() for after in thread_after: all_threads.append(after) for before in thread_before: all_threads.append(before) if(not is_iphone and not is_tablet): while(len(all_threads)>related_illust_cnt+1): no=int(random.random()*len(all_threads)) all_threads.remove(all_threads[no]) all_threads_cached=ApiObject.get_cached_object_list(all_threads) return all_threads_cached
def _append_one(data,user_id): if(not user_id): return bookmark=ApiObject.get_bookmark_of_user_id_for_write(user_id) if(bookmark): if(StackFeed._append_one_core(data,bookmark)): bookmark.put()
def del_message_list(self,user): if(self.request.get("user_id")!=user.user_id()): self.response.out.write(Alert.alert_msg("認証に失敗しました。",self.request.host)); return False bookmark=ApiObject.get_bookmark_of_user_id_for_write(user.user_id()) if(bookmark==None): self.response.out.write(Alert.alert_msg("ユーザデータが見つかりません。",self.request.host)); return False tweet_list=self.request.get_all("tweet_list") if(not tweet_list or len(tweet_list)==0): self.response.out.write(Alert.alert_msg("削除するツイートが選択されていません。",self.request.host)); return False for tweet in tweet_list: self.del_from_bookmark(bookmark,tweet) try: data=db.get(tweet) except: data=None if(data): if(data.from_user_id==user.user_id()): data.delete() bookmark.put() return True
def get_core(self): #パラメータ取得 method="" if(self.request.get("method")): method=self.request.get("method"); user_id="" if(self.request.get("user_id")): user_id=self.request.get("user_id") #返り値 dic={"method":method} #フィードクラス if(method=="getThreadList"): offset=0 if(self.request.get("offset")): try: offset=int(self.request.get("offset")) except: return {"status":"failed","message":"offset must be integer"} limit=10 if(self.request.get("limit")): try: limit=int(self.request.get("limit")) except: return {"status":"failed","message":"limit must be integer"} order=self.request.get("order") dic=ApiFeed.feed_get_thread_list(self,order,offset,limit) if(dic==None): return {"status":"failed","message":"bbs not found"} #return {"status":"failed","message":"debug error message"} dic=ApiObject.add_json_success_header(dic) return dic
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 withdraw(self,bookmark,your_bbs_count): user_id=self.request.get("user_id") if(not user_id): Alert.alert_msg_with_write(self,"ユーザIDが必要です。") return True user=users.get_current_user() bookmark=ApiObject.get_bookmark_of_user_id_for_write(user_id) #キャッシュから取得するのを防止 if(not bookmark): Alert.alert_msg_with_write(self,"ユーザが見つかりません。") return True if(OwnerCheck.check_bookmark(bookmark,user)): Alert.alert_msg_with_write(self,"退会する権限がありません。") return True is_english=CssDesign.is_english(self) if(your_bbs_count==0): #delete_user_thread(user.user_id()) #他人の掲示板に描いたイラストは慎重に削除する必要がある気がする bookmark.delete() msg="退会が完了しました。" if(is_english): msg="Complete" Alert.alert_msg_with_write(self,msg); else: msg="退会する前にレンタルしている掲示板を削除する必要があります。<BR>掲示板の削除はマイページのイラストタブで編集を押すことで行うことができます。<BR>残りの掲示板数:"+str(your_bbs_count) if(is_english): msg="You must delete your BBS before withdraw.<br/>You have "+str(your_bbs_count)+" BBS yet." Alert.alert_msg_with_write(self,msg) return True return True
def show_portal(self,user): self.redirect("./?order=chat") return is_iphone=CssDesign.is_iphone(self) is_tablet=CssDesign.is_tablet(self) show_room=Chat.get_room_object_list() is_admin=False if(OwnerCheck.is_admin(user)): is_admin=True #user_name=self.get_user_name(user) bookmark=None if(user): bookmark=ApiObject.get_bookmark_of_user_id(user.user_id()) template_values = { 'host': "./", 'is_iphone': is_iphone, 'is_tablet': is_tablet, 'bookmark': bookmark, 'redirect_url': self.request.path, 'mode': "chat", 'header_enable': False, 'room_list': show_room, 'is_admin':is_admin, #'user_name': user_name, 'is_english':CssDesign.is_english(self) } path = '/html/portal.html' self.response.out.write(template_select.render(path, template_values))
def bookmark_get_app_user_list(req): thread_key=req.request.get("app_key") bookmark_list=Bookmark.all().filter("app_key_list =",db.Key(thread_key)).fetch(limit=100) dic=[] for bookmark in bookmark_list: one_dic=ApiObject.create_user_object(req,bookmark) dic.append(one_dic) return dic
def get(self): SetUtf8.set() #Query文字列を取得 query=self.request.query_string; #RESULT result_dic={} request_no=0 #APIリクエストに分解 api_list=query.split(":") for api in api_list: #APIの引数を取得 args=api.split("&") #引数をDictionaryに分解 api_args={} for arg in args: params=arg.split("=") if(len(params)>=2): api_args[params[0]]=params[1] #呼び出しAPIのクラス名を決定 if(api_args.has_key("class")): #ダミーリクエストハンドラーを作成 req=HttpHandlerHook() req.request.args=api_args req.request.host=self.request.host #API呼び出し dic=None if(api_args["class"]=="api_bookmark"): dic=ApiBookmark.get_core(req) if(api_args["class"]=="api_user"): dic=ApiUser.get_core(req) if(api_args["class"]=="api_feed"): dic=ApiFeed.get_core(req) if(dic==None): logging.error("UnknownClass:"+api_args["class"]) else: result_dic["request"+str(request_no)]=dic request_no=request_no+1 ApiObject.write_json_core(self,result_dic)
def is_following(user,user_id,view_mode): if(view_mode): if(user): my_bookmark=ApiObject.get_bookmark_of_user_id(user.user_id()) if(my_bookmark): if(user_id in my_bookmark.user_list): return True return False
def get_user_name(user): if (not user): return "" user_id = user.user_id() bookmark = ApiObject.get_bookmark_of_user_id(user_id) if (not bookmark): return "" return bookmark.name
def get(self): is_iphone=CssDesign.is_iphone(self) page=1 page_unit=20 if(self.request.get("page")): page=int(self.request.get("page")) rank=Ranking.get_or_insert(BbsConst.THREAD_RANKING_KEY_NAME) ranking_mode=self.request.get("mode") ranking_id_list=rank.user_id_ranking_list[(page-1)*page_unit:page*page_unit] ranking_list=[] for user_id in ranking_id_list: obj=ApiObject.get_bookmark_of_user_id(user_id) if(obj): if(obj.disable_rankwatch): ranking_list.append(None) continue obj=ApiObject.create_user_object(self,obj) ranking_list.append(obj) user = users.get_current_user() user_rank=0 if(user): rank=Ranking.get_by_key_name(BbsConst.THREAD_RANKING_KEY_NAME) if(rank): user_rank=rank.get_user_rank(user.user_id()) template_values = { 'host': "./", 'is_iphone': is_iphone, 'user': user, 'user_rank': user_rank, 'redirect_url': self.request.path, 'mode': "ranking", 'header_enable': False, 'ranking_list': ranking_list, 'ranking_mode': ranking_mode, 'page': page, 'page_unit': page_unit } path = '/html/portal.html' self.response.out.write(template_select.render(path, template_values))
def get_tag_image(self,tag,page,unit): query = db.Query(MesThread,keys_only=True) #query.filter('illust_mode =', BbsConst.ILLUSTMODE_ILLUST) query.order('-create_date') query.filter('tag_list =', tag) cnt=query.count(limit=100) thread_key_list = query.fetch(limit=unit, offset=(page-1)*unit) thread_list=ApiObject.create_thread_object_list(self,thread_key_list,"pinterest") return {"thread_list":thread_list,"cnt":cnt}
def _consume_feed(user,view_mode,bookmark): if(user and bookmark): if(not view_mode): if(bookmark.new_feed_count or bookmark.new_my_feed_count): bookmark=ApiObject.get_bookmark_of_user_id_for_write(user.user_id()) bookmark.new_feed_count=0 bookmark.new_my_feed_count=0 bookmark.put() return bookmark
def get_user_name(self,user): if(user): bookmark=ApiObject.get_bookmark_of_user_id(user.user_id()) else: bookmark=None user_name="名無しさん" if(bookmark and bookmark.name and bookmark.name!="None"): user_name=bookmark.name return user_name
def user_list_to_user_object_list(req,user_list,fast): #ユーザIDだけの高速版 if(fast): dic=[] for one_user in user_list: one_dic=ApiObject.create_user_object_fast(req,one_user) dic.append(one_dic) return dic #名前などを含んだ低速版 bookmark_list=ApiObject.get_bookmark_list(user_list) dic=[] for one_user in user_list: bookmark=bookmark_list[one_user] if(bookmark): one_dic=ApiObject.create_user_object(req,bookmark) dic.append(one_dic) return dic