コード例 #1
0
ファイル: SchemeUpdate.py プロジェクト: abars/illustbook
	def update_thread(main):
		query=MesThread.all()
		
		total_cnt=0
		update_cnt=0
		
		offset=0
		if(main.request.get("from")):
			offset=int(main.request.get("from"))
			
		offset_to=10000
		if(main.request.get("to")):
			offset_to=int(main.request.get("to"))

		while(offset<offset_to):
			list=query.fetch(limit=1000,offset=offset)
			for thread in list:
				total_cnt=total_cnt+1
				if(not thread.image_key and thread.image):
					thread.image_key=db.get(thread.image)
					thread.put()
					update_cnt=update_cnt+1
					if(update_cnt>=500):
						break
			offset=offset+1000
			if(update_cnt>=500):
				break
		
		main.response.out.write("total"+str(total_cnt)+" update"+str(update_cnt))
コード例 #2
0
	def get_thread(bbs):
		if(not bbs):
			return None

		key=BbsConst.OBJECT_CACHE_HEADER+BbsConst.OBJECT_THREAD_CACHE_HEADER+str(bbs.key())

		display_n=8
		if(bbs.recent_thread_n):
			display_n=bbs.recent_thread_n
		if(display_n<0):
			return None

		data = memcache.get(key)
		if data:
			return data

		thread_query = MesThread.all().order("-create_date");
		thread_query.filter('bbs_key =', bbs)
		thread_list=thread_query.fetch(display_n);
		thread_array=[]
		for thread in thread_list:
			mee={'short': str(thread.short),
					'thread_key':str(thread.key()),
					'title':str(thread.title),
					'date':thread.date}
			thread_array.append(mee)
		memcache.add(key, thread_array, BbsConst.SIDEBAR_RECENT_THREAD_CACHE_TIME)
		return thread_array
コード例 #3
0
ファイル: RssFeed.py プロジェクト: abars/illustbook
    def generate_feed(bbs, bbs_key):
        url = MappingId.get_usr_url("http://www.illustbook.net/", bbs)
        feed = feedgenerator.Rss201rev2Feed(
            title=bbs.bbs_name, link=url, feed_url=url, description=bbs.summary, language="ja"
        )

        if bbs.bbs_mode == BbsConst.BBS_MODE_NO_IMAGE:
            entry_query = Entry.all().filter("bbs_key =", bbs)
            entry_query.order("-date")
            all_entry = entry_query.fetch(limit=20)
            for entry in all_entry:
                try:
                    thread = entry.thread_key
                except:
                    continue
                url2 = url + str(thread.key()) + ".html"
                txt = "" + entry.editor + "(" + str(entry.date) + ")<BR>"

                if entry.illust_reply:
                    txt += "<IMG SRC='http://www.illustbook.net/img?img_id='"
                    txt += str(entry.illust_reply_image_key.key()) + "'><BR>"
                txt += entry.content

                for res in entry.res_list:
                    response = db.get(res)
                    txt += "<BR><BR>" + response.editor + "(" + str(response.date) + ")<BR>"
                    txt += "" + response.content + "<BR>"

                feed.add_item(
                    title=thread.title,
                    link=url2,
                    description=txt,
                    author_email="",
                    author_name=entry.editor,
                    author_link=entry.homepage_addr,
                    pubdate=entry.date,
                )
        else:
            thread_query = MesThread.all().filter("bbs_key =", bbs)
            thread_query.order("-create_date")
            all_threads = thread_query.fetch(limit=20)

            for thread in all_threads:
                url2 = url + str(thread.key()) + ".html"
                if thread.image_key:
                    thumbnail = "http://www.illustbook.net/img?img_id=" + str(thread.image_key.key())
                    feed.add_item(
                        title=thread.title,
                        link=url2,
                        description="<IMG SRC=" + thumbnail + "><BR>" + thread.summary,
                        author_email="",
                        author_name=thread.author,
                        author_link=thread.homepage_addr,
                        pubdate=thread.create_date,
                    )
        result = feed.writeString("utf-8")

        return result
コード例 #4
0
	def _update_bbs(ds_obj):
		#現在はスレッド追加時にcached_thumbnail_keyを上書きしている
		#将来的にDSの以降などでkeyが変わる場合は以下のifをTrueにしてキャッシュを全更新すること
		if not ds_obj.cached_thumbnail_key:
			try:
				recent_thread=MesThread.all().filter("bbs_key =",ds_obj).order("-create_date").fetch(limit=1)
				if(recent_thread):
					image=recent_thread[0].image_key;
					if(image):
						ds_obj.cached_thumbnail_key=str(image.key());
						ds_obj.put()
			except:
				ds_obj.cached_thumbnail_key=""

		#スレッド数を更新する
		#スレッドの追加時にcached_threads_numにNoneが代入される
		if not ds_obj.cached_threads_num:
			ds_obj.cached_threads_num=MesThread.all().filter("bbs_key =",ds_obj).count()
			ds_obj.put()
コード例 #5
0
ファイル: CategoryList.py プロジェクト: abars/illustbook
	def _get_category_dic(bbs,new_category):
		#文字列->リスト
		category_list=[]
		if(bbs.category_list and bbs.category_list!=""):
			category_list=bbs.category_list.split(",")
		else:
			bbs.category_list=""
		
		#カテゴリとカウントの分離
		dic=[]
		category_found=False
		updated=False
		for text in category_list:
			m = re.search('(.*)\(([0-9]*)\)', text)
			if m:
				name=m.group(1)
				count=m.group(2)
			else:
				name=text
				count=-1
			if(name==""):
				continue

			#カテゴリの更新を行う場合
			if(new_category):
				if(name==new_category):
					count=-1
					category_found=True

			#更新リクエスト
			if(count==-1):
				count=MesThread.all().filter("bbs_key =",bbs).filter("category =",name).count(limit=1000)
				updated=True
				if(bbs.disable_category_sort):
					dic.append({"category":name,"count":count})
				else:
					dic.insert(0,{"category":name,"count":count})
			else:
				dic.append({"category":name,"count":count})
		
		#カテゴリが存在しなかったら新規追加
		if(new_category and (not category_found)):
			dic.insert(0,{"category":new_category,"count":1})
			updated=True

		#更新
		if(updated):
			CategoryList._put_category_dic(bbs,dic)
		
		return dic
コード例 #6
0
	def get(self):
		SetUtf8.set()

		#ランキング更新
		rank=Ranking.get_or_insert(BbsConst.THREAD_RANKING_KEY_NAME)
		rank.create_rank(self)
		ApiFeed.invalidate_cache();

		#キャッシュ取得
		cache=SiteAnalyzer.get_cache_from_db();

		#1日単位で習得
		#force=False
		#if(self.request.get("force")):
		#	force=True
		if(cache.date and len(cache.day_list)>=1):# and not force):
			day1_str=NicoTracker.get_day_string(cache.date)
			day2_str=NicoTracker.get_day_string(datetime.datetime.today())
			if(day1_str==day2_str):
				Alert.alert_msg_with_write(self,"ランキングを更新しました。統計情報はまだ1日が経過していないので計測していません。")
				return
		
		#コメント数と再生数を取得
		bbs_cnt=Bbs.all().count(limit=100000)
		illust_cnt=MesThread.all().count(limit=100000)
		entry_cnt=Entry.all().count(limit=100000)
		user_cnt=Bookmark.all().count(limit=100000)

		#書き込み
		day_str=NicoTracker.get_day_string(datetime.datetime.today())
		
		cache.entry_cnt_list.insert(0,entry_cnt)
		cache.illust_cnt_list.insert(0,illust_cnt)
		cache.bbs_cnt_list.insert(0,bbs_cnt)
		cache.user_cnt_list.insert(0,user_cnt)
		cache.day_list.insert(0,day_str)

		cache.bbs_n=bbs_cnt
		cache.illust_n=illust_cnt

		cache.put()

		Alert.alert_msg_with_write(self,"ランキングを更新しました。")
コード例 #7
0
ファイル: MyPage.py プロジェクト: abars/illustbook
	def delete_user_thread(self,user_id):
		query=MesThread.all().filter("user_id =",user_id)
		thread_list=query.fetch(limit=1000)
		for thread in thread_list:
			thread.delete()
コード例 #8
0
ファイル: Admin.py プロジェクト: abars/illustbook
	def get(self):
		user = users.get_current_user()
		is_admin=0
		is_high_admin=0
		account="ログインしていない状態"
		if(user):
			account="アカウント"+user.email()
			is_admin=1
			if(OwnerCheck.is_admin(user)):
				is_high_admin=1

		SetUtf8.set()

		thread_query = MesThread.all().order('-create_date')
		cnt=thread_query.count(10000)

		thread_page_unit=12
		thread_page=1
		if self.request.get("page"):
			thread_page = int(self.request.get("page"))
		thread_page_list=PageGenerate.generate_page(thread_page,cnt,thread_page_unit)

		comment_page=1
		only_comment=0
		if self.request.get("comment_page"):
			comment_page = int(self.request.get("comment_page"))
			only_comment=1

		if(not only_comment):
			thread_query.filter("illust_mode =",1)
			thread=thread_query.fetch(limit=thread_page_unit,offset=(thread_page-1)*thread_page_unit)
		
			new_moper_query=MesThread.all().order("-create_date")
			new_moper_query.filter("illust_mode =",2)
			new_moper=new_moper_query.fetch(limit=12)

			entry=None
			try:
				entry_query = Entry.all().order('-create_date')
				entry_query.filter("illust_reply =",1)
				entry=entry_query.fetch(limit=thread_page_unit,offset=(thread_page-1)*thread_page_unit)
			except:
				None
		else:
			thread=None
			new_moper=None
			entry=None

		comment=None
		try:
			comment_unit=7
			comment_query = Entry.all().order('-create_date')
			comment_query.filter("del_flag =", 1)
			comment=comment_query.fetch(limit=comment_unit,offset=comment_unit*(comment_page-1))
		except:
			None

		if(not only_comment):
			new_bbs_count=SiteAnalyzer.create_graph(self,0);
			new_illust_count=SiteAnalyzer.create_graph(self,1);
			new_entry_count=SiteAnalyzer.create_graph(self,2);
			new_user_count=SiteAnalyzer.create_graph(self,3);

			today_start = datetime.datetime.today()
			week_start = today_start - datetime.timedelta(days=7)
			month1_start = today_start - datetime.timedelta(days=31)
		
			weekly=Bbs.all().filter("date >=",week_start).count(limit=10000)
			monthly=Bbs.all().filter("date >=",month1_start).count(limit=10000)
		else:
			new_bbs_count=0
			new_illust_count=0
			new_entry_count=0
			new_user_count=0
			weekly=0
			monthly=0

		if os.environ["SERVER_SOFTWARE"].find("Development")!=-1:
			new_moper=[]
			
		host_url ="./"
		template_values = {
			'host': host_url,
			'threads':thread,
			'moper_threads':new_moper,
			'entries':entry,
			'comment':comment,
			'new_bbs_count':new_bbs_count,
			'new_entry_count':new_entry_count,
			'new_illust_count':new_illust_count,
			'new_user_count':new_user_count,
			'is_admin':is_admin,
			'is_high_admin': is_high_admin,
			'account':account,
			'url_logout':users.create_logout_url("./admin"),
			'url_login':users.create_login_url("./admin"),
			'page_list':thread_page_list,
			'page_url_base':"./admin?page=",
			'page':thread_page,
			'weekly':weekly,
			'monthly':monthly,
			'comment_page':comment_page,
			'only_comment': only_comment
			}
		path = '/html/admin.html'
		render=template_select.render(path, template_values)
		self.response.out.write(render)