Beispiel #1
0
 def load_comments(self, arg_list):
     entry = self.reddit.list_of_entries[self.lower_num]
     self.reddit.fetch_comment_page(entry['permalink'])
     c = Comments(self.reddit.comment_page[1]['data']['children'],
             self, entry['title'])
     c.mainloop()
     self.view()
Beispiel #2
0
def comment_page():
    coms = Comments(app.config['dsn'])
    nes = News(app.config['dsn'])
    if request.method == 'GET':
        now = datetime.datetime.now()
        comlist = coms.get_commentlist()
        nelist = nes.get_newlist()
        return render_template('comments.html', CommentList = comlist, NewList = nelist, current_time=now.ctime())
    elif 'comments_to_delete' in request.form:
        id_comments = request.form.getlist('comments_to_delete')
        for id_comment in id_comments:
            coms.delete_comment(id_comment)
        return redirect(url_for('comment_page'))
    elif 'comments_to_add' in request.form:
        id_comments = request.form.getlist('comments_to_add')
        for id_comment in id_comments:
            coms.add_comment(request.form['name'],request.form['article'],id_comment)
        return redirect(url_for('comment_page'))
    elif 'comments_to_update' in request.form:
        coms.update_comment(request.form['id_comment'], request.form['name'],request.form['article'])
        return redirect(url_for('comment_page'))
    elif 'comments_to_search' in request.form:
            searchList = coms.search_comment(request.form['name']);
            now = datetime.datetime.now()
            comlist = coms.get_commentlist()
            nelist = nes.get_newlist()
            return render_template('comments.html', CommentList = comlist, NewList = nelist, SearchList = searchList, current_time=now.ctime())
Beispiel #3
0
    def post(self):
        """
            
        """
        posts = self.get_query("UsersBlogPost")
        comments = self.get_query("Comments")
        title = self.request.get("Ctitle")
        comment = self.request.get("comment")
        user = self.get_username('username')
        if self.get_username('username'):
            if title is None or comment is None:
                error = True
                self.render('blogpost.html',
                            Ctitle=title,
                            comment=comment,
                            posts=posts,
                            comments=Comments,
                            user=user)

            else:
                title = self.request.get("Ctitle")
                comment = self.request.get("comment")
                postid = self.request.get("postid")
                userComment = Comments(user=user,
                                       comment=comment,
                                       title=title,
                                       commentId=postid)
                userComment.put()
                self.render('blogpost.html',
                            posts=posts,
                            comments=comments,
                            user=user)
        else:
            self.redirect('/login')
Beispiel #4
0
    def post(self):
        """
            
        """
        posts = self.get_query("UsersBlogPost")
        comments = self.get_query("Comments")
        title = self.request.get("Ctitle")
        comment = self.request.get("comment")
        user = self.get_username('username')
        if self.get_username('username'):
            if title is None or comment is None:
                error = True
                self.render('blogpost.html', Ctitle=title, comment=comment,
                        posts=posts, comments=Comments, user=user)

            else:
                title = self.request.get("Ctitle")
                comment = self.request.get("comment")
                postid = self.request.get("postid")
                userComment = Comments(user=user, comment=comment, title=title,
                                   commentId=postid)
                userComment.put()
                self.render('blogpost.html', posts=posts, comments=comments,
                        user=user)
        else:
            self.redirect('/login')
Beispiel #5
0
    def post(self, postid):
        if self.get_username('username'):
            user = self.get_username('username')
            task = self.request.get('task')
            post = self.get_posts('UsersBlogPost', postid)
            comments = self.get_post_comments('Comments', postid)
            if task == 'EditComment':
                editKey = self.request.get('edit')
                Etitle = self.request.get('Etitle')
                Ecomments = self.request.get('Ecomment')
                commentEdit = self.get_posts('Comments', editKey)
                commentEdit.comment = Ecomments
                commentEdit.title = Etitle
                # test whether current user is the comment's creator
                if user == commentEdit.user:
                    commentEdit.put()
                    return self.redirect('/')
                else:
                    editKey = self.request.get('edit')
                    message = "You are not the creator of this comment."
                    self.render_Html(post, user, comments, editKey,
                                     task, message)

            elif task == 'DeleteComment':
                editKey = self.request.get('delete')
                if self.get_posts('Comments', editKey):
                    deleteComment = self.get_posts('Comments', editKey)
                    # test whether current user is the comment's creator
                    if user == deleteComment.user:
                        deleteComment.delete()
                        self.render('singlepost.html', post=post, user=user,
                                    comments=comments)
                    else:
                        message = "You are not the creator of this comment."
                        self.render_Html(post, user, comments, editKey,
                                         task, message)
                else:
                    self.render('singlepost.html', post=post, user=user,
                                 comments=comments)
            else:
                # creates new comment
                error = False
                user = self.get_username("username")
                title = self.request.get('Ctitle')
                comment = self.request.get('comment')  # form comment
               # comments = self.get_post_comments('Comments', postid)  # comments stored in db
                post = self.get_posts('UsersBlogPost', postid)
                if self.test_for_none(comment) or self.test_for_none(title):
                    error = True
                    self.redirect('/blog/{}'.format(postid))
                else:
                    comment = Comments(user=user, comment=comment, title=title,
                                       commentId=str(postid))
                    comment.put()
                    self.render('singlepost.html', post=post, user=user,
                                comments=comments)
        else:
            self.redirect("/login")
Beispiel #6
0
 def post(self):
     page_id = int(self.request.get('id'))
     commentText = self.request.get('commentBox')
     print "############"
     print commentText
     comment = Comments(text=commentText, pageId=page_id)
     comment.key = comment.put()
     commentList.append(comment)
     page = blogpages[page_id]
     #self.response.out.write(constructBlogPost(page))
     self.response.out.write(self.constructComments(comment, page_id))
 def post(self):
     user_key = ndb.Key(urlsafe=self.request.get('user_key'))
     profile_user_obj = user_key.get()
     logged_user = users.get_current_user()
     logged_user = ndb.Key('MyUser', logged_user.user_id())
     logged_user = logged_user.get()
     if self.request.get('button') == "Follow":
         logged_user.following.append(str(profile_user_obj.name))
         logged_user.put()
         profile_user_obj.followers.append(str(logged_user.name))
         profile_user_obj.put()
         self.redirect('/')
     if self.request.get('button') == "Unfollow":
         logged_user.following.remove(str(profile_user_obj.name))
         logged_user.put()
         profile_user_obj.followers.remove(str(logged_user.name))
         profile_user_obj.put()
         self.redirect('/')
     if self.request.get('button') == "comment":
         post_key = ndb.Key(urlsafe=self.request.get('post'))
         post = post_key.get()
         comment = self.request.get('comment')
         if comment:
             comment_id = Comments()
             now = datetime.now()
             comment_id.posted_date = now
             comment_id.post_key = post_key
             comment_id.user_key = logged_user.name
             comment_id.comment = comment
             comment_id.put()
         self.redirect('/user_profile?user_key=%s' % user_key.urlsafe())
Beispiel #8
0
    def __init__(self, vw):
        self.cov = Coverage()
        self.comments = Comments()
        self.running = True
        self.cmt_changes = {}
        self.cmt_lock = Lock()
        self.stackvar_changes = {}
        self.stackvar_lock = Lock()
        self.syms = get_syms(vw)
        self.syms_lock = Lock()
        self.structs = {}  # get_structs(vw)
        self.structs_lock = Lock()

        self.filedata_by_sha = {}
        self.filedata_by_fname = {}
        for fname in vw.getFiles():
            sha256 = vw.getFileMeta(fname, 'sha256')
            mdict = dict(vw.getFileMetaDict(fname))
            mdict['name'] = fname
            mdict['maps'] = [
                mmap for mmap in vw.getMemoryMaps() if mmap[MAP_FNAME] == fname
            ]
            mdict['sha256'] = sha256
            self.filedata_by_sha[sha256] = mdict
            self.filedata_by_fname[fname] = mdict
Beispiel #9
0
 def post(self, commentId):
     comment = Comments.get_by_id(int(commentId))
     # Check person trying to edit comment. If not creator redirect
     if self.user and self.user.username == comment.author:
         # Check if comment else handle error
         if comment:
             # getting post info for the redirect URL
             post = comment.postId
             purpose = self.request.get("purpose")
             # get data from request
             entry = self.request.get("comment")
             if "delete" in purpose:
                 if not self.user:
                     self.redirect('/login')
                 else:
                     comment.delete()
                     time.sleep(1)
                     self.redirect('/blog/%s' % (post))
             else:
                 if not self.user:
                     self.redirect('/login')
                 else:
                     if entry:
                         comment.comment = entry
                         comment.put()
                         time.sleep(1)
                         self.redirect('/blog/%s' % (post))
         else:
             self.redirect('/errorhandler/2/blog')
     else:
         self.redirect('/unauth/2/blog')
Beispiel #10
0
	def get(self):
		show_all_key = ''
		if self.request.get('show_all_key'):
			show_all_key = ndb.Key(urlsafe=self.request.get('show_all_key'))
		self.response.headers['Content-Type'] = 'text/html'

		url = ''
		url_string = ''
		post = ''

		welcome = 'Welcome back'
		myuser = None
		posts = []
		comment_dictonary = {}
		user = users.get_current_user()
		if user:
			url = users.create_logout_url(self.request.uri)
			url_string = 'logout'
			myuser_key = ndb.Key('MyUser', user.user_id())
			myuser = myuser_key.get()

			post = BlobCollection.query().order(-BlobCollection.posted_date).fetch(limit=50)
			if myuser == None:
				welcome = 'Welcome to the Instagram'
				myuser = MyUser(id=user.user_id())
				myuser.name = user.email()
				myuser.put()
			key_list = []
			if myuser:
				for follo in myuser.following:
					use = MyUser.query().filter(MyUser.name == follo)
					use = use.fetch(10)
					for ussss in use:
						key_list.append(ussss.key)
				# raise UserWarning(key_list)
				for p in post:
					if p.user_key == myuser.key or p.user_key in key_list:
						posts.append(p)
				for pst in posts:
					comments = Comments.query().filter(Comments.post_key == pst.key).order(-Comments.posted_date)
					comment_dictonary[pst.key] = comments

		else:
			url = users.create_login_url(self.request.uri)
			url_string = 'login'
		# raise UserWarning(posts)
		template_values = {
			'url' : url,
			'show_all_key' : show_all_key,
			'posts': posts,
			'comment_dictonary': comment_dictonary,
			'upload_url': blobstore.create_upload_url('/upload'),
			'url_string' : url_string,
			'user' : user,
			'welcome' : welcome,
			'myuser' : myuser
		}

		template = JINJA_ENVIRONMENT.get_template('main.html')
		self.response.write(template.render(template_values))
Beispiel #11
0
 def constructComments(self, comment, page_id):
     thisPageComments_query = Comments.query(Comments.pageId == page_id)
     thisPageComments = thisPageComments_query.fetch()
     commentList = []
     for comment in thisPageComments:
         if (comment.text != None):
             commentList.append(comment.text)
     this = blogpages[page_id]
     commentHTML = this.commentsAsHTML(commentList)
     this.commentSection = commentHTML
     return self.constructBlogPost(this)
    def get_publish_info4discovery(publish, *params):
        result = {}
        longitude = params[0]
        latitude = params[1]
        user_id = params[2]
        try:
            if user_id == 0:
                result["attribute"] = -1
            else:
                result["attribute"] = UserPublishRelationMethods.get_attribute_by_user_and_publish(user_id, publish.id)

            result["publish_id"] = publish.id
            result["created_at"] = Datetimes.utc2east8(publish.created_at)
            result["win"] = UserPublishRelationMethods.get_win_attribute_count_by_publish(publish)
            result["lost"] = UserPublishRelationMethods.get_lost_attribute_count_by_publish(publish)

            if publish.user and publish.user.userextension:
                result["user_nickname"] = publish.user.userextension.nickname
            else:
                result["user_nickname"] = ""

            temp_image = Users.get_user_image(publish.user)
            result["user_small_image"] = temp_image["small_user_image"]

            temp_publish_images = Publishes.get_publish_images(publish)
            result["publish_image_url"] = temp_publish_images["publish_image_url"]
            result["publish_image_big_url"] = temp_publish_images["publish_image_big_url"]
            result["publish_image_medium_url"] = temp_publish_images["publish_image_medium_url"]
            result["publish_image_small_url"] = temp_publish_images["publish_image_small_url"]
            result["PM2_5"] = publish.PM2_5

            result["comment"] = Comments.get_by_publish(publish.id)
            result["content"] = publish.content

            result["bonus"] = RedEnvelopes.get_red_envelope_by_publish(publish.id)

            s = publish.shop
            big_category = ShopCategories.get_shop_big_category(publish.shop.category)

            if not big_category:
                big_category = ShopCategories.get_category_default()
            big_category_key = big_category.id
            result["big_category_name"] = big_category.name
            result["big_category_key"] = big_category.id

            if not big_category_key:
                result["category_operation"] = {}
            else:
                result["category_operation"] = PublishCategories.get_category_info_by_shop_category(big_category)
        except Exception as ex:
            Logs.print_current_function_name_and_line_number(ex)

        return result
Beispiel #13
0
 def get(self, commentId):
     comment = Comments.get_by_id(int(commentId))
     # Check if comment else handle error.
     # Also check that user accessing created comment
     if comment:
         if not self.user:
             self.redirect('/login')
         if self.user.username != comment.author:
             self.redirect('/unauth/2/blog')
         else:
             self.render("edit-comment.html", comment=comment)
     else:
         self.redirect('/errorhandler/2/blog')
Beispiel #14
0
 def __init__(self, bv):
     self.cov = Coverage()
     self.comments = Comments()
     self.fhash = get_fhash(bv.file.filename)
     self.running = True
     self.cmt_changes = {}
     self.cmt_lock = Lock()
     self.stackvar_changes = {}
     self.stackvar_lock = Lock()
     self.data_syms = get_syms(bv, SymbolType.DataSymbol)
     self.func_syms = get_syms(bv, SymbolType.FunctionSymbol)
     self.syms_lock = Lock()
     self.structs = get_structs(bv)
     self.structs_lock = Lock()
Beispiel #15
0
	def post(self):
		logged_user = users.get_current_user()
		logged_user = ndb.Key('MyUser', logged_user.user_id())
		logged_user = logged_user.get()
		if self.request.get('button') == "comment":
			post_key = ndb.Key(urlsafe=self.request.get('post'))
			post = post_key.get()
			comment = self.request.get('comment')
			if comment:
				comment_id = Comments()
				now = datetime.now()
				comment_id.posted_date = now
				comment_id.post_key = post_key
				comment_id.user_key = logged_user.name
				comment_id.comment = comment
				comment_id.put()
			self.redirect('/')
    def post(self):

        user = users.get_current_user()

        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()

        comment = self.request.get('comment')
        post_id = self.request.get('query')
        post_key = ndb.Key(Post, long(post_id))
        post = post_key.get()
        new_comment = Comments(comment=comment, comment_by=myuser_key)
        post.comments.append(new_comment)
        post.put()
        self.redirect('/')
Beispiel #17
0
 def get(self, post_id):
     key = db.Key.from_path('blog_post', int(post_id))
     post = db.get(key)
     # Check to see if post exists and handles error if it does not
     if post:
         author = blog_post.get_by_id(int(post_id)).author
         postId = int(post_id)
         userId = self.user.key().id()
         comments = Comments.all().filter("postId =",
                                          postId).order("created")
         self.render('new_post_page.html',
                     post=post,
                     author=author,
                     comments=comments,
                     userId=userId)
     else:
         self.redirect('/errorhandler/2/blog')
Beispiel #18
0
    def _write_comment_files(self):
        # Write the comment files.
        index = 1
        for worksheet in self.workbook.worksheets():
            if not worksheet.has_comments:
                continue

            comment = Comments()
            comment._set_xml_writer(self._filename('xl/comments'
                                                   + str(index) + '.xml'))
            comment._assemble_xml_file(worksheet.comments_list)
            index += 1
    def get(self):
        comment_dictonary = {}
        show_all_key = ''
        if self.request.get('show_all_key'):
            show_all_key = ndb.Key(urlsafe=self.request.get('show_all_key'))
        user_key = ndb.Key(urlsafe=self.request.get('user_key'))
        profile_user_obj = user_key.get()
        logged_user = users.get_current_user()
        logged_user = ndb.Key('MyUser', logged_user.user_id())
        logged_user = logged_user.get()
        is_following = False
        if profile_user_obj != logged_user:
            if profile_user_obj.name in logged_user.following:
                is_following = True
        posts = BlobCollection.query().filter(
            BlobCollection.user_key == user_key).order(
                -BlobCollection.posted_date)
        for pst in posts:
            comments = Comments.query().filter(
                Comments.post_key == pst.key).order(-Comments.posted_date)
            comment_dictonary[pst.key] = comments
        # len_post = 0
        # for p in posts:
        #

        len_followers = len(profile_user_obj.followers)
        len_following = len(profile_user_obj.following)
        len_posts = 0
        for p in posts:
            len_posts += 1
        template_values = {
            'len_posts': len_posts,
            'show_all_key': show_all_key,
            'len_followers': len_followers,
            'comment_dictonary': comment_dictonary,
            'profile_user_obj': profile_user_obj,
            'len_following': len_following,
            'logged_user': logged_user,
            'posts': posts,
            'user_key': user_key.urlsafe(),
            'is_following': is_following,
        }

        template = JINJA_ENVIRONMENT.get_template('user_profile.html')
        self.response.write(template.render(template_values))
Beispiel #20
0
def index(): 
	from pagination import Pagination
	from blog import Blog, Images
	from comments import Comments
	from adminsettings import Adminsettings, Cifrar
	Adminsettings(db)
	Blog(db,ckeditor), Images(db)
	Comments(db)
	settings = db(db.adminsettings.id>0).select(db.adminsettings.ALL).first()
	session.publishing=False
	session.preview=False
	records=db(db.blog.id>0).count()
	items_per_page=settings.blogitems
	pag=Pagination(records, items_per_page)
	posts = db(db.blog.public==True).select(db.blog.ALL, orderby=~db.blog.id, limitby=pag.limitby(), cache=(cache.ram, 5), cacheable=True)
	lastposts = db(db.blog.public==True).select(db.blog.ALL, orderby=~db.blog.id, limitby=(0,10), cache=(cache.ram, 150), cacheable=True)
	
	return dict(posts=posts, pagination=pag, records=records, items_per_page=items_per_page, lastposts=lastposts)
Beispiel #21
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        action = self.request.get('button')
        user = users.get_current_user()
        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()

        if action == 'post':
            comment = self.request.get('comment')
            key = self.request.GET['key']
            post_key = ndb.Key('Post', int(key))
            post = post_key.get()
            now = datetime.now()

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()
            new_comment = Comments(text=comment,
                                   comment_time=str(now),
                                   comment_user=myuser_key)
            post.comments.append(new_comment)
            post.put()
            self.redirect('/')
Beispiel #22
0
    def get_hot_shop_compute_data(shop, user_id=0):
        result = dict()
        now = Datetimes.get_now()
        now_utc = Datetimes.transfer_datetime(now, is_utc=False)
        now_utc = Datetimes.naive_to_aware(now_utc)
        seven_days_before = Datetimes.get_some_day(7, 0, now)
        seven_days_before_utc = Datetimes.transfer_datetime(seven_days_before, is_utc=False)
        seven_days_before_utc = Datetimes.naive_to_aware(seven_days_before_utc)

        publishes = Publishes.get_shown_publishes(user_id).filter(
            shop_id=shop.id, created_at__gte=seven_days_before_utc, created_at__lte=now_utc)
        result["publish_count"] = publishes.count()
        persons = publishes.values("user_id").distinct()
        result["person_count"] = persons.count()
        pm2_5s = publishes.filter(PM2_5__gt=-1)
        result["PM2_5_count"] = pm2_5s.count()
        result["comment_count"] = sum([Comments.get_count_by_publish(p.id) for p in publishes])
        result["win_count"] = \
            sum([UserPublishRelationMethods.get_win_attribute_count_by_publish(p) for p in publishes])
        result["lost_count"] = \
            sum([UserPublishRelationMethods.get_lost_attribute_count_by_publish(p) for p in publishes])
        result["recommended_count"] = UserShopRelationMethods.get_recommended_count_by_shop(shop)
        result["not_recommended_count"] = UserShopRelationMethods.get_not_recommended_count_by_shop(shop)
        return result
Beispiel #23
0
 def post(self, post_id):
     if not self.user:
         return self.redirect('/login')
     key = db.Key.from_path('blog_post', int(post_id))
     post = db.get(key)
     # Check to see if post exists and handles error if it does not
     if post:
         postId = int(post_id)
         userId = self.user.key().id()
         author = self.user.username
         comment = self.request.get("comment")
         if comment:
             comment = Comments(postId=postId,
                                userid=userId,
                                author=author,
                                comment=comment)
             comment.put()
             time.sleep(1)
             comments = Comments.all().filter("postId =",
                                              postId).order("created")
             self.render("new_post_page.html",
                         post=post,
                         author=author,
                         userId=userId,
                         comments=comments)
         else:
             comments = Comments.all().filter("postId =",
                                              postId).order("created")
             self.render("new_post_page.html",
                         post=post,
                         author=author,
                         comments=comments,
                         userId=userId,
                         error="Please enter comment before submitting")
     else:
         self.redirect('/errorhandler/2/blog')
Beispiel #24
0
            Comments.log = True
        if command == "process":
            process = 1
        if command == "bm":  # short for Build Model
            bm = 1

# Если параметр crawl был задан, мы сначала всё скрапим
# И только потом возвращаемся в код
if crawl == 1:
    os.system("scrapy crawl games")
    # Если мы заскрапили то автоматически надо эти данные обработать
    # и сохранить
    process = 1
    bm = 1
else:
    Comments.load_values(Comments)

if process == 1:
    Comments.process_data(Comments)
    bm = 1
else:
    Comments.load_data_from_file(Comments)

if bm == 1:
    Comments.parse_data(Comments)
else:
    Comments.load_model(Comments)

if process == 1 or bm == 1:
    print("\n===============\nvvvvvvvvvvvvvvvv\n")
    print("Shape of data is:\n{}".format(Comments.data.shape))
Beispiel #25
0
def show():
	session.publishing=False
	from blog import Blog, Images
	from regnews import Regnews
	from comments import Comments

	from gluon.tools import Recaptcha

	Blog(db,ckeditor), Images(db)
	Regnews(db)	
	Comments(db)
	images=None
	if auth.has_membership('administradores') or auth.has_membership('superadministradores'):
		#logger.debug(session.preview)
		if not request.args(0):
			redirect(URL('blog','index'))			
		if session.preview:
			from blog import Draft
			Draft(db,ckeditor)
			if request.args(0).isdigit():

				post=db.draft(db.draft.id==request.args(0)) or redirect(URL('blog','index'))
			else:
				post=db.draft(db.draft.urlfriendly==request.args(0)) or redirect(URL('blog','index'))
		else:
			if request.args(0).isdigit():			
				post=db.blog(db.blog.id==request.args(0)) or redirect(URL('blog','index'))	
			else:
				post=db.blog(db.blog.urlfriendly==request.args(0)) or redirect(URL('blog','index'))	
	else:
		if not request.args(0):
			redirect(URL('blog','index'))
		if request.args(0).isdigit():			
			post=db.blog((db.blog.id==request.args(0)) & (db.blog.public==True) ) or redirect(URL('blog','index'))
		else:
			post=db.blog((db.blog.urlfriendly==request.args(0)) & (db.blog.public==True) ) or redirect(URL('blog','index'))
	if post.image!=None:
		images=db.images(post.image)
		#logger.debug(images)

	comment = Field('comment', 'text', label="Comentario",notnull=True, requires=IS_NOT_EMPTY(error_message="Debes escribir un comentario"))

	if auth.is_logged_in():
		form = SQLFORM.factory(comment, submit_button = 'Comentar', formstyle='bootstrap')
	else:
		name = Field('name', 'string', label="Nombre", length=50, requires=IS_NOT_EMPTY(error_message="Debe identificarse con un nombre"))
		email = Field('email', 'string', length=128, requires=IS_EMAIL(error_message="email incorrecto"))
		website = Field('website','string', length=128, widget=lambda field,value: SQLFORM.widgets.string.widget(field, value, _placeholder='Opcional'))
		rnews = Field('rnews', 'bool', default=True) 
		captcha = Recaptcha(request, '6Lf849gSAAAAAD2YgjNJxrelMp7-hPnTNZyyf4pD', '6Lf849gSAAAAAOgabgN9kc5YO1hhEws_un0btbbf',use_ssl=True, error_message='Inválido', label='Verificar:', options='theme:"clean", lang:"es"')
		# antispam= Field("anti_spam", widget=recaptcha, default='')		
		form = SQLFORM.factory(name, rnews, email, website, comment,  submit_button = 'Comentar')

		form[0].append(captcha)

	if form.errors.has_key('captcha'):
		response.flash='Captcha inválido'

	elif form.validate(keepvalues=False):
		data=form.vars

		try:
			if auth.is_logged_in():
				if request.args(0).isdigit():
					db.comments.insert(comment=data.comment, user=auth.user.id, blog=request.args(0))
				else:
					db.comments.insert(comment=data.comment, user=auth.user.id, blog=db(db.blog.urlfriendly==request.args(0)).select().first()["id"] )
			else:
				reg=db(db.regnews.email==data.email).select()
				if len(reg)==0:
					id=db.regnews.insert(email=data.email, name=data.name, news=data.rnews, website=data.website)
					if request.args(0).isdigit():
						db.comments.insert(comment=data.comment, blog=request.args(0), regnews=id)
					else:
						db.comments.insert(comment=data.comment, blog=db(db.blog.urlfriendly==request.args(0)).select().first()["id"], regnews=id)
				else: 
					if request.args(0).isdigit():
						db.comments.insert(comment=data.comment, blog=request.args(0), regnews=reg[0].id)
					else:
						db.comments.insert(comment=data.comment, blog=db(db.blog.urlfriendly==request.args(0)).select().first()["id"], regnews=reg[0].id)

			db.commit()
			response.flash = "Comentario publicado"
			
			#redirect(URL('blog','show', args=request.args(0)))
		except Exception, ex:
			logger.debug(ex)
			db.rollback()
			response.flash="Su comentario no se pudo enviar. Inténtelo de nuevo"
Beispiel #26
0
 def comments(self):
     return Comments(self)
Beispiel #27
0
    def parse_json_comments(self, response):

        print("==============\nstart parsing json\n===============")

        num = re.compile(
            r'[0-9]+\.?[0-9]*')  # Регулярное выражение для определения числа

        data = json.loads(response.body)
        ut.write_html(self.dest + "comments.html", data['html'])

        html = data['html'].replace('<br>',
                                    '\n')  # Заменяем для целостности комента

        selector = Selector(text=html)
        selector.remove_namespaces()

        output = ""

        # Используем регулярное выражение для получения только полных комментариев
        review_boxes = selector.xpath(
            "//div[re:test(@class, '\Areview_box\s*\Z')]")
        for review in review_boxes:
            output += "\n=======================\n"

            if review.css('div.persona_name') is None:
                continue  # Если такого не существует пропускаем

            persona_name = review.css('div.persona_name')

            if persona_name.css('a::text').extract_first() is None:
                name = "i have to search in span"
                continue
            else:
                name = str(persona_name.css('a::text').extract_first())

            if persona_name.css('a::attr(href)').extract_first() is None:
                url = "have to search in another place"
                continue
            else:
                url = str(persona_name.css('a::attr(href)').extract_first())

            if url != "None" and url is not None:
                person_id = url.split('/')[-2]
            else:
                person_id = "Doesn't exist"

            if review.css(
                    'div.num_owned_games a::text').extract_first() is None:
                num_owned_games = "Didn't find"
                continue
            else:
                num_owned_games = str(
                    review.css('div.num_owned_games a::text').extract_first()
                ).split(' ')[-1]
                num_owned_games = num_owned_games.replace(',', '')
                num_owned_games = num_owned_games.replace('.', '')

            if review.css('div.num_reviews a::text').extract_first() is None:
                num_reviews = "Didn't find"
                continue
            else:
                num_reviews_text = review.css(
                    'div.num_reviews a::text').extract_first().strip()
                if num.match(num_reviews_text):
                    num_reviews = (num.findall(num_reviews_text))[0].strip()
                    num_reviews = num_reviews.replace(',', '')
                    num_reviews = num_reviews.replace('.', '')
                else:
                    num_reviews = "0"

            if review.xpath('.//div[contains(@class, "title ellipsis")]/text()'
                            ).extract_first() is None:
                grade = "Didn't find"
                continue
            else:
                grade = review.xpath(
                    './/div[contains(@class, "title ellipsis")]/text()'
                ).extract_first()
                if grade == "Рекомендую":
                    grade = "1"
                else:
                    grade = "0"

            if review.xpath('.//div[contains(@class, "hours ellipsis")]/text()'
                            ).extract_first() is None:
                hours = "Didn't find"
                continue
            else:
                hours = review.xpath(
                    './/div[contains(@class, "hours ellipsis")]/text()'
                ).extract_first()
                hours = hours.split(' ')[-2].replace('.', '')
                hours = hours.replace(',', '')

            if review.css('div.vote_info::text').extract_first() is None:
                num_useful = "Didn't find"
                num_funny = "Didn't find"
                continue
            else:
                useful = "Not found"
                funny = "Not found"

                num_useful = '0'
                num_funny = '0'

                votes_info = review.css('div.vote_info::text').extract()

                for _ in votes_info:
                    votes = _.splitlines()
                    for vote in votes:
                        if 'полезным' in vote:
                            useful = vote.strip()
                            num_useful = num.findall(useful)[0].strip()
                        elif 'забавным' in vote:
                            funny = vote.strip()
                            num_funny = num.findall(funny)[0].strip()

            if review.css('div.content::text').extract_first() is None:
                text = "None"
                continue
            else:
                text = review.css('div.content::text').extract_first()

            num_reviews = num.findall(num_reviews_text)[0]

            output += "Name\tis:\t{}\n".format(name)
            output += "Url\tis:\t{}\n".format(url)
            output += "Id \tis:\t{}\n".format(person_id)
            output += "Owned games:\t{}\n".format(num_owned_games)
            output += "Num reviews:\t{}\n".format(num_reviews)
            output += "Grade\tis:\t{}\n".format(grade)
            output += "Ingame hours:\t{}\n".format(hours)

            output += "People think it helpful:\t{}\n".format(num_useful)
            output += "People think it funny:\t\t{}\n".format(num_funny)

            # output += "Text:\n{}\n".format(text)

            Comments.add_comment(Comments, text, num_owned_games, num_reviews,
                                 grade, hours, num_useful, num_funny)

            output += "=======================\n"

        ut.write_html(self.dest + "reviewers.txt", output)

        # output = ""
        # comments = selector.css('div.review_box').css('div.content::text').extract()
        # for comment in comments:
        #     comment = comment.strip()
        #     if not comment:
        #         continue    # Пропускаем если строчка пустая
        #     output += "\n=============================\n"
        #     output += comment
        #     output += "\n=============================\n"

        # ut.write_html(self.dest + 'comments.txt', output)

        print("==============\nended parsing json\n===============")
Beispiel #28
0
def preprocessing_intermediate_remove_comment(intermediate_data):
    """Preprocessing intermediate data: Remove comment"""
    remover = Comments(style="c")
    data = remover.strip(intermediate_data)
    return data
Beispiel #29
0
def test_comments():
    print("\nTesting submission comments")
    assert Comments.commentFunction() != ""
Beispiel #30
0
 def get(self):
     c = Comments()
     c.fixCommentsForTopics()
     c.fixCommentsForCategories()
Beispiel #31
0
def strip_comments(text, preserve_lines=False):
    return Comments('json', preserve_lines).strip(text)
Beispiel #32
0
 def __init__(self, **config):
     self.comments = Comments(**config)
     super(Gist, self).__init__(**config)
Beispiel #33
0
def sanitize_json(text, preserve_lines=False):
    return strip_dangling_commas(
        Comments('json', preserve_lines).strip(text), preserve_lines)
Beispiel #34
0
import sys
import requests

from flask import Flask, Blueprint, request, jsonify
from flask_cors import CORS
from comments import Comments
app = Flask(__name__)
bp = Blueprint('comments', __name__, url_prefix='/comments')

comments = Comments()

@bp.route("/<thread_id>", methods=["GET"])
def get_thread(thread_id):
    thread = comments.get_thread(thread_id)
    print('get_thread:', thread_id, thread)
    return jsonify({'thread': thread})

@bp.route("/<thread_id>", methods=["PUT"])
def add(thread_id):
    json_data = request.get_json()
    added_comment = comments.add(thread_id, json_data)
    print('added_comment:', added_comment)
    return jsonify({'comment': added_comment})


if __name__ == "__main__":
    port = 6001
    if len(sys.argv) >= 2:
        port = sys.argv[1]

    app.register_blueprint(bp)
Beispiel #35
0
    def post(self, postid):
        if self.get_username('username'):
            user = self.get_username('username')
            task = self.request.get('task')
            post = self.get_posts('UsersBlogPost', postid)
            comments = self.get_post_comments('Comments', postid)
            if task == 'EditComment':
                editKey = self.request.get('edit')
                Etitle = self.request.get('Etitle')
                Ecomments = self.request.get('Ecomment')
                commentEdit = self.get_posts('Comments', editKey)
                commentEdit.comment = Ecomments
                commentEdit.title = Etitle
                # test whether current user is the comment's creator
                if user == commentEdit.user:
                    commentEdit.put()
                    return self.redirect('/')
                else:
                    editKey = self.request.get('edit')
                    message = "You are not the creator of this comment."
                    self.render_Html(post, user, comments, editKey, task,
                                     message)

            elif task == 'DeleteComment':
                editKey = self.request.get('delete')
                if self.get_posts('Comments', editKey):
                    deleteComment = self.get_posts('Comments', editKey)
                    # test whether current user is the comment's creator
                    if user == deleteComment.user:
                        deleteComment.delete()
                        self.render('singlepost.html',
                                    post=post,
                                    user=user,
                                    comments=comments)
                    else:
                        message = "You are not the creator of this comment."
                        self.render_Html(post, user, comments, editKey, task,
                                         message)
                else:
                    self.render('singlepost.html',
                                post=post,
                                user=user,
                                comments=comments)
            else:
                # creates new comment
                error = False
                user = self.get_username("username")
                title = self.request.get('Ctitle')
                comment = self.request.get('comment')  # form comment
                # comments = self.get_post_comments('Comments', postid)  # comments stored in db
                post = self.get_posts('UsersBlogPost', postid)
                if self.test_for_none(comment) or self.test_for_none(title):
                    error = True
                    self.redirect('/blog/{}'.format(postid))
                else:
                    comment = Comments(user=user,
                                       comment=comment,
                                       title=title,
                                       commentId=str(postid))
                    comment.put()
                    self.render('singlepost.html',
                                post=post,
                                user=user,
                                comments=comments)
        else:
            self.redirect("/login")
Beispiel #36
0
 def closed(self, reason):
     print('=' * 5, GamesSpider.gameCount, '=' * 5)
     print("\n\noutputting values \n\n")
     Comments.ouput_values(Comments)
     print("Saving values")
     Comments.save_values(Comments)
Beispiel #37
0
 def get(self):
     c = Comments()
     c.fixCommentsForTopics()
     c.fixCommentsForCategories()