def show_post(sid, pid): if request.method == "POST": newComment = Comment(message=request.form['message'], user_id=session['uid'], post_id=pid, parent_id=int(request.form["cid"])) print " message is %s" % request.form["message"] dbsession.add(newComment) dbsession.commit() return newComment.id if "uid" in session: vote = dbsession.query(Vote).filter_by( user_id=session["uid"]).filter_by(post_id=pid).first() if vote: g.post_vote = vote.direction else: g.post_vote = "-" sub = dbsession.query(Sub).filter_by(id=sid).one() post = dbsession.query(Post).filter_by(id=pid).one() comments = dbsession.query(Comment).filter_by(post_id=post.id).filter_by( parent_id=0) print "comments objs %s" % str(comments) #print "comment author: %s"%post.user.username #print "user obj: %s"%str(post.user) #user = dbsession.query(User).filter_by(id=session['uid']).one() return render_template('show_post.html', sub=sub, post=post, comments=comments, get_comments=get_comments, get_author=get_author) #, username=user.username )
def crawl(engine, initial_url, start_date, end_date, delay=1): """ Get the title and description of each workout of the day between start and end date. Initializes with a seed url. """ # create a session to hook up with the sqlite db Session = sessionmaker(bind=engine) session = Session() # get the date range date_range = end_date - start_date # make a list of dates dates = [ start_date + timedelta(date) for date in range(0, date_range.days) ] # initialize a web browser browser = webdriver.Firefox() # ensure we wait for DOM to populate browser.implicitly_wait(10) # The url for workouts of the days are formatted as # https://www.crossfit.com/workouts/2016/01/15 # where the last three parameters are year, month, day. for date in dates: # build the url abs_url = initial_url + "/{:02d}/{:02d}/{:02d}".format( date.year, date.month, date.day) # get the contents title, description, comments = getWorkoutAndComments(abs_url, browser) # and write them to the db w = Workout(title=title, description=description) session.add(w) session.commit() print("Added {} to the DB.".format(title)) for (username, text) in comments: u = User(username=username) session.add(u) session.commit() c = Comment(text=text, user_id=u.id, workout_id=w.id) session.add(c) session.commit() print("Added {} user comments to the DB.".format( session.query(Comment).count())) # delay between requests # time.sleep(delay) return session
def newComment(offering_id): if 'username' not in login_session: return redirect('/login') offering = session.query(Offering).filter_by(id=offering_id).one() if request.method == 'POST': newComment = Comment(body=request.form['body'], offering_id=offering.id, user_id=login_session['user_id']) session.add(newComment) flash('Comment Added') session.commit() return redirect(url_for('offeringDetail', offering_id=offering_id))
def comment_post(id): if request.cookies['is_logged_in'] != 'yes': return redirect('/') comment = Comment(post_id=id, author=request.cookies['name'], message=request.form['message'], date=datetime.now(), likes=0) session.add(comment) session.commit() return redirect('/post/' + id)
def new_comment(post_id): if request.method == 'GET': log('200') return render_template('new_blog.html') if request.method == 'POST': log('302') if 'username' not in login_session: return redirect(url_for('login')) comment = request.form.get('comment') uid = login_session['id'] new_comment = Comment(uid=uid, pid=post_id, comment=comment) session.add(new_comment) session.commit() return redirect(url_for('get_post', post_id=post_id))
def post_comment(sid, pid, cid): print "IN POST COMMENT" if 'uid' not in session: return redirect(url_for('login')) print "ok" if request.method == 'POST': newComment = Comment(message=request.form['message'], user_id=session['uid'], post_id=pid, parent_id=cid) print " message is %s" % request.form["message"] dbsession.add(newComment) dbsession.commit() return str(newComment.id) print "this is A GET request" return redirect(url_for("show_posts"))
def createComment(): if 'username' not in login_session: return redirect('/login') idea_id = request.form['id'] person_id = login_session['person_id'] person = session.query(Person).filter_by(id=person_id).one() comment = Comment() comment.text = request.form['text'] comment.person_id = login_session['person_id'] comment.idea_id = idea_id comment.person = person session.add(comment) session.commit() return redirect("http://0.0.0.0.xip.io:5000/all_ideas")
def write_comment(sid, pid, cid): if 'uid' not in session: return redirect(url_for('login')) if request.method == 'POST': newComment = Comment(message=request.form['message'], user_id=session['uid'], post_id=pid, parent_id=cid) dbsession.add(newComment) dbsession.commit() return redirect(url_for('show_post', sid=sid, pid=pid)) if cid != 0: element = dbsession.query(Comment).filter_by(id=cid).one() else: element = dbsession.query(Post).filter_by(id=pid).one() return render_template('write_comment.html', element=element, sid=sid, pid=pid, cid=cid)
def comment_handler(blog_id): val_email = request.cookies.get('email') email = check_secure_val(val_email) try: user = session.query(User).filter_by(email=email).first() except: session.rollback() if request.method == 'POST': data = request.get_json() content = data['content'] if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') comment = Comment(content=content.strip(), user_id=user.id, post_id=blog_id, user_name=user.name, user_image=user.image) session.add(comment) try: session.commit() except: session.rollback() # session.close() r = make_response(json.dumps(user.name, ensure_ascii=False).encode('utf-8')) r.headers['Content-type'] = 'application/json; charset=utf-8' return r
def comments(): try: if request.method == "POST": session = DBSession() comment = request.form.get("comment", None) time = request.form.get("time", None) video = request.form.get("video_link", None) comment_value = Comment(data=comment, timestamp=time, video_id=video, user_id=current_user.get_id(), parent_id=1) session.add(comment_value) session.commit() data = ["video_detail", video] if (current_user.email == "*****@*****.**"): session = DBSession() video = session.query(Videos).all() login_user(user) return render_template("admin_dashboard.html", videos=video) return redirect(url_for('lesson_detail')) except Exception as e: print e
title='CHELSEA WON THE PRIMER LEAGUE', content='Chelsea won the title, AGAIN! YESS 3 Nill', type='Sports', status='live') session.add(new_post) session.commit() new_post = Post(uid=1, title='HOW I FEEL AFTER A COLD SHOWER', content='I FEEL FREAKING PERFECT, IT MAKES ME WANT TO FLY', type='Health', status='live') session.add(new_post) session.commit() new_comment = Comment(pid=1, uid=3, comment='History of lies!!!!') session.add(new_comment) session.commit() new_comment = Comment(pid=1, uid=1, comment='Why, could you explain!!!!') session.add(new_comment) session.commit() new_comment = Comment(pid=2, uid=3, comment='This is not doing me any good!') session.add(new_comment) session.commit() new_comment = Comment( pid=3, uid=2, comment='What the heck are you saying? this doesnt help!') session.add(new_comment) session.commit()
picture= 'http://entertainment.ie//images_content/rectangle/620x372/christopher-reeve-superman.jpg' ) session.add(User1) session.commit() offering1 = Offering(user_id=1, title="Godchild", date="October") session.add(offering1) session.commit() tag1 = Tag(tag_name="Babygrow", offering=offering1) session.add(tag1) session.commit() tag2 = Tag(tag_name="Novelty", offering=offering1) session.add(tag2) session.commit() comment1 = Comment(user_id=1, body="That looks great", offering=offering1) session.add(comment1) session.commit() offering2 = Offering(user_id=1, title="Super", date="October") session.add(offering2) session.commit() comment2 = Comment(user_id=1, body="Fabulous", offering=offering2) session.add(comment2) session.commit() print "Offerings added"