Ejemplo n.º 1
0
	def update_entry(main):
		query=Entry.all()
		query.filter("illust_reply =",1)
		
		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 entry in list:
				total_cnt=total_cnt+1
				if(entry.illust_reply_image_key):#not entry.illust_reply_image_key and entry.illust_reply_image):
					#entry.illust_reply_image_key=db.get(entry.illust_reply_image)
					entry.date=entry.create_date
					entry.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))
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
	def get_illust_reply(bbs,page,col_num):
		all_entries = None
		entries_num = 0
		try:
			entry_query = Entry.all().filter("bbs_key =", bbs)
			entry_query.filter("illust_reply =",1)
			entry_query.filter("del_flag =",1)
			entry_query.order("-date")
			entries_num=entry_query.count()
			all_entries=entry_query.fetch(limit=col_num, offset=(page-1)*col_num)
		except:
			None
		return {"entry":all_entries,"count":entries_num}
		
Ejemplo n.º 4
0
	def get(self):
		SetUtf8.set()

		user = users.get_current_user()

		is_admin=0
		if(user):
			if(OwnerCheck.is_admin(user)):
				is_admin=1
		
		if(not is_admin):
			Alert.alert_msg_with_write(self,"管理者権限が必要です。");
			return
		
		message=""
		new_code=self.request.get('code')
		if(new_code):
			if(len(new_code)>=8):		
				memcache.set("spamcheck",new_code)
				message="updated check code to "+new_code
			else:
				message="too short check code"

		checkcode=SpamCheck.get_check_code()

		query=Entry.all()
		thread=None
		try:
			thread=db.get(checkcode)
		except:
			thread=None
		if(thread):
			query.filter("thread_key =",thread)
		entrys=query.fetch(limit=1000)

		ret=""
		spam_detected=0
		for entry in entrys:
			if(SpamCheck.check_with_thread(entry,checkcode)):
				ret+=entry.content+"<BR>"
				spam_detected=1
		if(not spam_detected):
			ret="SpamNotFound"
		
		form="code:"+checkcode+"<BR>"+message+"<BR>"
		form+="<form method='GET' action='spam_check'>thread_key:<input type='text' name='code' size=40><input type='submit' value='UPDATE'></form>";
		
		Alert.alert_msg_with_write(self,"<H2>SPAM CHECKER</H2><H3>CHECK CODE</H3>"+form+"<H3>SPAM LIST</H3>"+ret+"<BR><BR><A HREF='./spam_delete'>DELETE ALL</A>")		
Ejemplo n.º 5
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,"ランキングを更新しました。")
Ejemplo n.º 6
0
	def delete_thread_core(thread):
		#イラストの総数の更新リクエスト
		thread.bbs_key.cached_threads_num=None
		thread.bbs_key.put()
		if(thread.user_id):
			ApiUser.invalidate_thread_count(thread.user_id)

		#レスの削除
		entry_query=Entry.all().filter("thread_key =",thread)
		for entry in entry_query:
			if(entry.illust_reply_image_key):
				entry.illust_reply_image_key.delete()

		#画像の削除
		if(thread.image_key):
			if(thread.image_key.chunk_list_key):
				for key in thread.image_key.chunk_list_key:
					db.get(key).delete()
			thread.image_key.delete()

		thread.delete()
Ejemplo n.º 7
0
	def get(self):
		SetUtf8.set()

		user = users.get_current_user()
		
		is_admin=0
		if(user):
			if(OwnerCheck.is_admin(user)):
				is_admin=1
		
		if(not is_admin):
			self.response.out.write(Alert.alert_msg("管理者権限が必要です。",self.request.host));
			return

		checkcode=SpamCheck.get_check_code()		

		query=Entry.all()
		thread=None
		try:
			thread=db.get(checkcode)
		except:
			thread=None
		if(thread):
			query.filter("thread_key =",thread)
		entrys=query.fetch(limit=1000)
		
		ret=0
		aborted=""

		for entry in entrys:
			if(SpamCheck.check_with_thread(entry,checkcode)):
				entry.delete()
				ret=ret+1
				if(ret>=250):
					aborted="ABORTED"
					break;

		RecentCommentCache.invalidate(None);
		self.response.out.write(Alert.alert_msg("<H2>SPAM DELETE RESULT</H2>"+aborted+"<H2>TOTAL</H2>DELETE CNT:"+str(ret),self.request.host))		
Ejemplo n.º 8
0
	def post(self):
		SetUtf8.set()
		is_english=CssDesign.is_english(self)

		#エラーコードはFlash向けかどうか
		is_flash=False
		if(self.request.get('image')):
			is_flash=True

		#書き込み対象のコメントを取得
		if(self.request.get("entry_key")):	#上書きモード
			entry = db.get(self.request.get("entry_key"))
			overwrite = True
		else:
			entry = Entry()
			overwrite = False
	
		#コメント
		if(self.request.get('comment')):
			entry.content = self.request.get('comment')
		else:
			if(self.request.get('image')):
				entry.content = ""
			else:
				if(is_english):
					self.write_status(is_flash,"Please input comment");
				else:
					self.write_status(is_flash,"コメントを入力して下さい。");
				return

		#名前
		if(self.request.get('author')):
			entry.editor = cgi.escape(self.request.get('author'))
		else:
			entry.editor = "no_name"
			if(is_english):
				self.write_status(is_flash,"Please input name");
			else:
				self.write_status(is_flash,"名前を入力して下さい。");
			return
			

		if(not self.request.get('image')):
			if(self.request.get("seed")!=BbsConst.SUBMIT_SEED):
				self.write_status(is_flash,"シードが一致しません。");
				return

		if(self.request.get('mail_addr')):
			entry.mail=self.request.get('mail_addr')
		else:
			entry.mail=""
		
		if(self.request.get('homepage_addr') and self.request.get('homepage_addr')!="http://"):
			entry.homepage_addr=self.request.get('homepage_addr')
		else:
			entry.homepage_addr=""

		user = users.get_current_user()

		thread=db.Key(self.request.get("thread_key"))
		bbs = db.get(self.request.get("bbs_key"))

		if(SpamCheck.check_all(self,entry.content,self.request.get("remote_host"),user,bbs,is_flash,is_english)):
			return

		#二重投稿ブロック
		if(entry.content!="" and memcache.get("add_entry_double_block")==entry.content):
			if(is_flash):
				self.write_status(is_flash,"二重投稿を検出しました。時間を置いて、再度、投稿して下さい。");
			else:
				url=MappingThreadId.get_thread_url("./",bbs,db.get(self.request.get("thread_key")))
				self.redirect(str(url))
			return
		
		#コメント禁止
		if(db.get(thread).prohibit_comment):
			self.write_status(is_flash,"このイラストへのコメントは禁止されています。");
			return
		
		#書き込み権限確認
		if(bbs.comment_login_require):
			if(not(user)):
				self.write_status(is_flash,"この掲示板ではコメントする際にログインが必須です。");
				return

		#上書き権限確認
		if(overwrite):
			bbs=db.get(self.request.get("bbs_key"))
			if(OwnerCheck.check(bbs,user)):
				if(user and entry.user_id!=user.user_id()):
					self.write_status(is_flash,"上書き投稿する権限がありません。");
					return
		
		#イラストの設定
		delete_thread_image=None
		if(self.request.get('image')):
			if(overwrite):
				delete_thread_image=entry.illust_reply_image_key
			timage=ThreadImage()
			timage.bbs_key=bbs

			if(self.request.get("base64") and self.request.get("base64")=="1"):
				timage.image=db.Blob(base64.b64decode(self.request.get("image")))
				timage.thumbnail=db.Blob(base64.b64decode(self.request.get("thumbnail")))
			else:
				timage.image=db.Blob(self.request.get("image"))
				timage.thumbnail=db.Blob(self.request.get("thumbnail"))
			timage.thumbnail2=None
			timage.illust_mode=1;
			try:
				timage.put()
			except:
				if(is_english):
					self.write_status(is_flash,"Too big image");
				else:
					self.write_status(is_flash,"画像サイズが大きすぎます。");
				return

			entry.illust_reply=1
			entry.illust_reply_image_key=timage
		else:
			entry.content=cgi.escape(entry.content)
			entry.content=EscapeComment.auto_link(entry.content)

		entry.content=EscapeComment.escape_br(entry.content)

		entry.thread_key = thread
		entry.bbs_key = bbs
		entry.del_flag = 1
		if(self.request.get("regulation")):
			entry.adult=int(self.request.get("regulation"))

		#プロフィールにリンクするか
		link_to_profile=StackFeed.is_link_to_profile(self)
		if(link_to_profile and user):
			entry.user_id=user.user_id()

		#スレッドを取得
		thread = db.get(self.request.get("thread_key"))

		#基本情報を設定
		if(not overwrite):
			self.set_basic_info(entry,thread)

		#保存
		if(not SyncPut.put_sync(entry)):
			message="コメントの投稿は成功しましたが表示が遅延しています。反映まで数分お待ちください。"
			memcache.set(BbsConst.OBJECT_THREAD_MESSAGE_HEADER+str(thread.key()),message,BbsConst.OBJECT_THREAD_MESSAGE_CACHE_TIME)
			memcache.set(BbsConst.OBJECT_BBS_MESSAGE_HEADER+str(bbs.key()),message,BbsConst.OBJECT_BBS_MESSAGE_CACHE_TIME)

		#スレッドと掲示板の情報を更新
		if(not overwrite):
			self.update_thread_and_bbs_information(thread,bbs,entry)

		#上書き投稿時の昔のイラストの削除
		if(delete_thread_image):
			delete_thread_image.delete()

		#ステータスコードを出力
		if(self.request.get('image')):
			self.response.headers ['Content-type'] = "text/html;charset=utf-8"  
			self.response.out.write("success")			
		else:
			url=MappingThreadId.get_thread_url("./",bbs,thread)
			if(self.request.get("redirect_url")):
				url=self.request.get("redirect_url")
			self.redirect(str(url))

		#二重投稿ブロック
		memcache.set("add_entry_double_block",self.request.get("comment"),30)
		
		#ランキング
		is_owner=False
		if(thread.user_id and entry.user_id and thread.user_id == entry.user_id):
			is_owner=True
		if(not is_owner): #自分のスレッドへのコメントはランキングに反映しない
			Ranking.add_rank_global(thread,BbsConst.SCORE_ENTRY)

		#フィード
		if(not link_to_profile):
			user=None
		try:
			StackFeed.feed_new_comment_thread(user,thread,entry)
		except:
			logging.error("new entry stackfeed add error")
Ejemplo n.º 9
0
	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)