コード例 #1
0
def main():
    number_comments = 0
    check_inbox()
    delete_if_downvoted()
    comments = reddit.subreddit('test').comments(limit=100)

    for comment in comments:
        regex = re.search(MEMORABLE_QUOTE_REGEX, comment.body)
        subname = comment.subreddit.display_name
        allowed = not select(b for b in Bannedsub if b.name == subname)[:]
        fresh = not select(c for c in Comment if c.id == comment.id)[:]

        if regex and allowed and fresh:
            # select a random person from db and create image
            person = select(x.name for x in Historicalfigure)[:][int(random() *
                                                                     numfigs)]
            number_comments = number_comments + 1
            image = build_image(regex.group(0), comment.id, person)
            Comment(id=comment.id, url=image)
            comment.reply(make_comment(image))

            print(
                regex.group(0) + '\n' + '-_-_-' +
                comment.subreddit.display_name + '\n' + comment.permalink +
                '\n')
    print('NEXT')
コード例 #2
0
ファイル: app.py プロジェクト: davidparienti/myNetwork
def getpost(post_id):
    if redirect_is_not_logged(session) != True:
        return redirect_is_not_logged(session)
    post_exist = Post.query.filter_by(id=post_id).first()
    if post_exist is not None:
        page_name = post_exist.title
        if request.method == 'POST':
            message = request.form.get('message', None)
            if message:
                comment = Comment(message=message,
                                  user_id=session['id'],
                                  post_id=post_id,
                                  created=datetime.datetime.now())
                db.session.add(comment)
                db.session.commit()

        get_post = db.session.execute(
            'SELECT post.* , user.full_name ,  user.profil_media , user.username , count(DISTINCT jaime.id) as nb_like , count(DISTINCT jaime2.id) as liked, count(DISTINCT comment.id) as nb_comment , strftime(\'%d/%m/%Y %H:%M\', datetime(post.created)) as created  FROM post LEFT JOIN comment ON comment.post_id = post.id LEFT JOIN jaime ON jaime.post_id = post.id LEFT JOIN jaime as jaime2 ON jaime2.post_id = post.id AND jaime2.user_id = :myid JOIN user ON user.id = post.user_id LEFT JOIN Followerfollowing ON Followerfollowing.user_id = :myid  LEFT JOIN Followerfollowing as Followerfollowing_2 ON Followerfollowing_2.user_id_2 = :myid WHERE post.id = :post_id',
            {
                'myid': session['id'],
                'post_id': post_id
            }).first()
        get_comments = db.session.execute(
            'SELECT comment.* , user.profil_media , user.full_name , user.username , strftime(\'%d/%m/%Y %H:%M\', datetime(comment.created)) as created  FROM comment JOIN user ON user.id = comment.user_id  WHERE comment.post_id = :post_id ORDER BY created DESC',
            {'post_id': post_id})
        return render_template('post.html',
                               page_name=page_name,
                               Post=get_post,
                               Comments=get_comments)
    else:
        return redirect(url_for('index'))
コード例 #3
0
def addComment():
    post_data = request.get_json()
    body = post_data.get('body')
    article_id = db.session.query(Article).filter(
        Article.article_url == post_data.get('article_url')).all()
    if (article_id == []):
        response_object = {
            'status':
            'Failure',
            'message':
            "Article Url " + post_data.get('article_url') + " does not exist"
        }
        return jsonify(response_object), 404
    authenticated = False if request.authorization == None else verify_password(
        request.authorization.username, request.authorization.password)
    owner_id = None if authenticated == False else db.session.query(
        User).filter(
            User.username == request.authorization.username).all()[0].id
    db.session.add(
        Comment(body=body, article_id=article_id[0].id, owner_id=owner_id))
    db.session.commit()
    response_object = {
        'status': 'success',
        'message': "Comment" + body + " was added!"
    }

    return jsonify(response_object), 201
コード例 #4
0
ファイル: comment.py プロジェクト: MirageJian/Varkt-Blog
 async def post(self):
     body = self.loads_request_body()
     self.session.add(
         Comment(idArticle=body["idArticle"],
                 content=body["content"],
                 author=body["author"],
                 createdAt=datetime.utcnow()))
     self.session.commit()
コード例 #5
0
def addComment(post_id):
    user = find_logged_user()
    post = find_post(post_id)
    comment = Comment(user_id=user.id,
                      post_id=post.id,
                      content=request.form['content'],
                      date_added=datetime.datetime.now())
    session.add(comment)
    session.commit()
    return redirect('/showpost/%s#comments' % post_id)
コード例 #6
0
def artcle(url,url2):
    ''' Article driver for all generic article pages. '''
    if request.method == 'POST':
        if 'title' in request.form and 'message' in request.form:
            z = Comment(title=request.form['title'],message=request.form['message'],poster=current_user.id,postername = current_user.name, article=url2)
            db.session.add(z)
            db.session.commit()
    post = Post.query.filter_by(topic=url,id=url2).first()
    if post:
        return render_template('article.html',art = post,title=post.title,pidd=post.id)
    addAttack(request.url)
    return render_template('genericpage.html',body='Article not found!',title='Error')
コード例 #7
0
ファイル: index.py プロジェクト: sxy52011/MyNewInfor
def news_comment():
    news_id = request.form.get('news_id')             #新闻ID
    news_comment = request.form.get('comment')        #用户输入的评论到具体内容
    user_id = session.get('user_id')                  #用户ID
    c = Comment(news_id = news_id ,user_id = user_id,content=news_comment)         #生成一条评论表对应的数据
    db.session.add(c)            #将评论写入到数据库
    db.session.commit()          #提交

    msg={}
    msg['code'] = '200'
    msg['data'] = c.to_dict()
    return jsonify(msg)
コード例 #8
0
ファイル: feed.py プロジェクト: WitchoutName/kivy-retter
 def setup(self, *args, **kwargs):
     self.ids.dialog_author.text = self.thread.author.username
     self.ids.dialog_author.secondary_text = str(self.thread.date)
     if self.thread.description:
         self.ids.dialog_description.text = self.thread.description
     if self.thread.image:
         self.ids.dialog_img.source = f"media/thread/{self.thread.id}.png"
     self.ids.dialog_likes.text = str(self.thread.likes)
     print(self.thread.comments)
     comments = self.thread.comments
     self.ids.dialog_comments.text = f"Comments({len(comments) if comments else 0})"
     self.ids.dialog_like_btn.on_press = lambda: like_post(
         self.thread, self, "dialog_likes")
     self.ids.comment_submit.on_press = lambda: self.add_comment(
         self.ids.coment_message.text)
     if comments:
         self.ids.comments.clear_widgets()
         for comment in comments:
             self.ids.comments.add_widget(Comment(comment))
コード例 #9
0
ファイル: shared.py プロジェクト: Watchful1/ModQueueNotifier
def ingest_comments(subreddit, database):
	for comment in subreddit.sub_object.comments(limit=None):
		if database.session.query(Comment).filter_by(comment_id=comment.id).count() > 0:
			break

		db_submission = database.session.query(Submission).filter_by(submission_id=comment.link_id[3:]).first()
		if db_submission is None:
			db_submission = add_submission(subreddit, database, None, comment.submission)

		db_user = database.session.query(User).filter_by(name=comment.author.name).first()
		if db_user is None:
			db_user = User(name=comment.author.name)
			database.session.add(db_user)

		db_comment = database.session.merge(Comment(
			comment_id=comment.id,
			author=db_user,
			submission=db_submission,
			created=datetime.utcfromtimestamp(comment.created_utc),
			subreddit_id=subreddit.sub_id
		))

		if db_submission.is_restricted and comment.author.name != "CustomModBot":
			author_result = author_restricted(subreddit, database, db_user)
			if author_result is not None:
				counters.user_comments.labels(subreddit=subreddit.name, result="filtered").inc()
				action_comment(subreddit, db_comment, author_result)
			else:
				counters.user_comments.labels(subreddit=subreddit.name, result="allowed").inc()
		else:
			counters.user_comments.labels(subreddit=subreddit.name, result="allowed").inc()

			if not db_submission.is_notified:
				age_in_hours = int((datetime.utcnow() - db_submission.created).total_seconds()) / (60 * 60)
				if age_in_hours < 2 and database.session.query(Comment).filter(Comment.submission == db_submission).count() > 50:
					good_comments, bad_comments = get_comments_for_thread(subreddit, database, db_submission.submission_id)
					notify_string = f"Non-moderated submission is {round(age_in_hours, 1)} hours old with {len(good_comments)} comments from good accounts and {len(bad_comments)} comments from accounts with low history: <https://www.reddit.com/r/{subreddit.name}/comments/{db_submission.submission_id}/>"
					log.info(notify_string)
					#requests.post(subreddit.webhook, data={"content": notify_string})
					db_submission.is_notified = True
コード例 #10
0
def ingest_comments(subreddit, database):
    for comment in subreddit.sub_object.comments(limit=None):
        if database.session.query(Comment).filter_by(
                comment_id=comment.id).count() > 0:
            break

        db_submission = database.session.query(Submission).filter_by(
            submission_id=comment.link_id[3:]).first()
        if db_submission is None:
            db_submission = add_submission(subreddit, database, None,
                                           comment.submission)

        db_user = database.session.query(User).filter_by(
            name=comment.author.name).first()
        if db_user is None:
            db_user = User(name=comment.author.name)
            database.session.add(db_user)

        db_comment = database.session.merge(
            Comment(comment_id=comment.id,
                    author=db_user,
                    submission=db_submission,
                    created=datetime.utcfromtimestamp(comment.created_utc)))

        if db_submission.is_restricted and comment.author.name != "CustomModBot":
            author_result = author_restricted(subreddit, database, db_user)
            if author_result is not None:
                counters.user_comments.labels(subreddit=subreddit.name,
                                              result="filtered").inc()
                comment.mod.remove(mod_note=f"filtered: {author_result}")
                db_comment.is_removed = True
                log.info(
                    f"Comment {comment.id} by u/{comment.author.name} removed: {author_result}"
                )
            else:
                counters.user_comments.labels(subreddit=subreddit.name,
                                              result="allowed").inc()
        else:
            counters.user_comments.labels(subreddit=subreddit.name,
                                          result="allowed").inc()
コード例 #11
0
ファイル: main.py プロジェクト: hyungmogu/multi-user-blog
    def post(self, post_id):
        data = json.loads(self.request.body)
        cookie_val = self.request.cookies.get("user_id")
        blog = Blog.get_by_id(int(post_id))
        title = data["title"]
        content = data["content"]
        user = User.get_by_id(int(cookie_val.split("|")[0]))

        if not self.blog_exists(blog):
            message = "Invalid. The requested page doesn't exist."
            self.send_response(404, message)
            return
        if not self.is_signed_in(cookie_val):
            message = "Invalid. Only signed in User can post comments"
            self.send_response(401, message)
            return
        if not (title and content):
            message = "Invalid. Title and texts must not be empty."
            self.send_response(400, message)
            return

        comment = Comment(title=title, content=content, blog=blog, author=user)
        comment_id = comment.put().id()

        message = json.dumps({
            "success":
            "Comment successfully added to database.",
            "id":
            comment_id,
            "title":
            title,
            "content":
            content,
            "author":
            user.username,
            "date_created":
            comment.date_created.strftime("%B %d %Y %I:%M%p")
        })
        self.send_response(200, message)
コード例 #12
0
def add_comment():

    content = request.form.get('comment_content')

    note_id = request.form.get('note_id')

    comment = Comment(content=content)

    user_id = session['user_id']

    user = User.query.filter(User.id == user_id).first()

    comment.author = user

    note = Note.query.filter(Note.id == note_id).first()

    comment.note = note

    db.session.add(comment)

    db.session.commit()

    return redirect(url_for('note.detail', note_id=note_id))
コード例 #13
0
            db_submission = Submission(submission_id=comment.submission_id,
                                       created=comment.created,
                                       is_restricted=False)
            database_prod.session.add(db_submission)

        comment_author_name = comment.author.name
        db_user = database_prod.session.query(User).filter_by(
            name=comment_author_name).first()
        if db_user is None:
            new_users += 1
            db_user = database_prod.session.merge(
                User(name=comment_author_name))
        database_prod.session.merge(
            Comment(comment_id=comment.comment_id,
                    author=db_user,
                    submission=db_submission,
                    created=comment.created,
                    subreddit_id=3,
                    karma=comment.karma,
                    is_removed=comment.is_removed,
                    is_deleted=comment.is_deleted))
        count += 1
        if count % 1000 == 0:
            log.info(
                f"{count}/{total_comments}: {new_submissions}|{new_users}")
            database_prod.session.commit()

    log.info(f"{count}/{total_comments}: {new_submissions}|{new_users}")
    database_prod.close()
    database_new.close()
コード例 #14
0
    def post(self, post_id):
        post_button = self.request.get("postbutton").split(',')
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)
        user_key = self.user.key()

        # When the user clicks 'like'
        if post_button[0] == "like":
            # If the user already liked the post, decrease likes_total (unlike
            # post)
            if self.user.key().id() != post.postuser.key().id():
                if user_key in post.likedby:
                    post.likedby.remove(user_key)
                    post.likes_total -= 1
                    post.put()
                else:
                    # Increase the likes_total, and append the user to 'likedby'
                    # list
                    post.likes_total += 1
                    post.likedby.append(user_key)
                    post.put()
                self.redirect('/blog/%s' % str(post.key().id()))
                return

        elif post_button[0] == "delete":
            if self.user.key().id() != post.postuser.key().id():
                post.delete()
                self.redirect('/')
                return
            else:
                self.redirect('/login')
                return

        # Add new comment to the post
        elif post_button[0] == "comment":
            if self.user:
                comment_text = self.request.get("comment_text")
                commentuser = self.user
                newcomment = Comment(parent=post,
                                     commentuser=commentuser,
                                     commenttext=comment_text)
                newcomment.put()
                self.redirect('/blog/%s' % str(post.key().id()))
                return
            else:
                self.redirect('/login')
                return

        # Edit existing post comment
        elif post_button[0] == "editcomment":
            key = db.Key.from_path('Comment',
                                   int(post_button[1]),
                                   parent=post.key())
            c = db.get(key)
            # If the logged in user is also the comment author, open the
            # comment in edit mode
            if c.commentuser.key().id() == self.user.key().id():
                c.editmode = True
                c.put()
            self.redirect('/blog/%s' % str(post.key().id()))
            return

        # Delete existing comment
        elif post_button[0] == "deletecomment":
            key = db.Key.from_path('Comment',
                                   int(post_button[1]),
                                   parent=post.key())
            c = db.get(key)
            if c and self.user.key().id() == c.commentuser.key().id():
                c.delete()
                self.redirect('/blog/%s' % str(post.key().id()))
                return
            else:
                self.redirect('/login')
                return

        # Submit the edited comment to the db
        elif post_button[0] == "submitcommentedit":
            key = db.Key.from_path('Comment',
                                   int(post_button[1]),
                                   parent=post.key())
            c = db.get(key)
            if c and self.user.key().id() == c.commentuser.key().id():
                c.commenttext = self.request.get("comment_edit_text")
                c.editmode = False
                c.put()
                self.redirect('/blog/%s' % str(post.key().id()))
                return

        else:
            comments = db.GqlQuery(
                "SELECT * FROM Comment WHERE ANCESTOR IS :1 ", post)
            for c in comments:
                c.editmode = True
                c.put()
                self.redirect('/blog/%s' % str(post.key().id()))
コード例 #15
0
			database.session.commit()
			database.engine.dispose()
			sys.exit()

		db_submission = database.session.query(Submission).filter_by(submission_id=submission_id).first()
		if db_submission is None:
			db_submission = Submission(
				submission_id=submission_id,
				created=comment_created,
				is_restricted=False
			)
			database.session.add(db_submission)

		db_user = database.session.query(User).filter_by(name=comment['author']).first()
		if db_user is None:
			db_user = database.session.merge(User(name=comment['author']))

		db_comment = database.session.merge(Comment(
			comment_id=comment['id'],
			author=db_user,
			submission=db_submission,
			created=comment_created,
			subreddit_id=3
		))

		if count % 1000 == 0:
			log.info(f"{count} : {(comment_created.strftime('%Y-%m-%d'))}")
			database.session.commit()

database.engine.dispose()
コード例 #16
0
        if db_submission is None:
            db_submission = Submission(submission_id=submission_id,
                                       created=comment_created,
                                       is_restricted=False)
            database.session.add(db_submission)

        db_user = database.session.query(User).filter_by(
            name=comment['author']).first()
        if db_user is None:
            db_user = database.session.merge(User(name=comment['author']))

        if database.session.query(Comment).filter_by(
                comment_id=comment['id']).first() is not None:
            log.info(f"{count} : {(comment_created.strftime('%Y-%m-%d'))}")
            log.info(f"Found existing comment, exiting")
            database.session.commit()
            database.engine.dispose()
            sys.exit()

        db_comment = database.session.merge(
            Comment(comment_id=comment['id'],
                    author=db_user,
                    submission=db_submission,
                    created=comment_created))

        if count % 1000 == 0:
            log.info(f"{count} : {(comment_created.strftime('%Y-%m-%d'))}")
            database.session.commit()

database.engine.dispose()