Ejemplo n.º 1
0
def blog(request,context):
    z=[]
    f=bform(request.POST)
    tmp=request.session['tmp']
    b=posts.objects.get(id=context)
    a=open('blog'+'/'+'blogs'+'/'+b.pl)
    k=a.readlines()
    e=comments.objects.filter(post=b.comment)
    for each in e:
        o=open('blog'+'/'+'command'+'/'+each.com)
        z.append((each.date,o.readlines()))
    if request.method=='POST':
        if request.POST.get('submit'):
            if f.is_valid():
                cd=f.cleaned_data
                time=datetime.datetime.now().time()
                fle=open('blog'+'/'+'command'+'/'+str(time),'a')
                fle.write(cd['com'])
                now=datetime.date.today()
                p=comments(post=b.comment,com=str(time),date=str(now.day)+'/'+str(now.month)+'/'+str(now.year))
                p.save()
                return HttpResponseRedirect('/'+context+'/blog')
        if request.POST.get('home'):
            if tmp:return HttpResponseRedirect('/userr')
            else:return HttpResponseRedirect('/login')
        if request.POST.get('logout'):return HttpResponseRedirect('/login')
    return render(request,'blog.html',{'f':f,'k':k,'tmp':tmp,'b':b,'z':z})
Ejemplo n.º 2
0
def view(id):
    if request.method == "GET":
        info = blogs.get(blogs.c.id == id)
        form = CommentsForm()
        comment = comments.filter(comments.c.blog_id == id)
        return {'form':form, 'info':info, 'comment':comment}

    if request.method == "POST":
        form = CommentsForm()
        flag = form.validate(request.params)
        if flag:
            info = comments(**form.data)
            info.blog_id = id
            info.save()
        return redirect('/view/%s' % id)
Ejemplo n.º 3
0
def index():
    if request.method == 'POST':
        comment = request.form.get('text')
        if comment == '':
            flash('Заполните поле "Сообщение"', 'post_message')
        else:
            add_comment = comments(name=current_user.username,
                                   comment=comment,
                                   is_active=True,
                                   user=current_user)
            db.session.add(add_comment)
            db.session.commit()
            flash('Комментарий успешно добавлен', 'view_comment')
        return redirect(url_for('index'))
    users_comments = comments.query.all()
    users_comments.reverse()
    return render_template('index.html', users_comments=users_comments)
Ejemplo n.º 4
0
def delete_negative_comment(insta_username):
    try:
        user_id = get_user_id(insta_username)
        media_id = get_user_post(insta_username)
        request_url = (base_url + 'media/%s/comments/?access_token=%s') % (
            media_id, access_token)
        print 'GET request url : %s' % request_url
        comment_info = requests.get(request_url).json()
        if comment_info['meta']['code'] == 200:
            # Check if we have comments on the post
            if len(comment_info['data']) > 0:
                # And then read them one by one
                for comment in comment_info['data']:
                    comment_id = comment['id']
                    comment_text = comment['text']
                    blob = TextBlob(comment_text,
                                    analyzer=NaiveBayesAnalyzer())
                    print blob.sentiment
                    print blob.sentiment.classification
                    comment = models.comments(user_id=user_id,
                                              media_id=media_id,
                                              comment_id=comment_id,
                                              comment_text=comment_text)
                    comment.save()
                    if blob.sentiment.p_neg > blob.sentiment.p_pos:
                        comment_id = comment['id']
                        delete_url = (base_url +
                                      'media/%s/comments/%s/?access_token=%s'
                                      ) % (media_id, comment_id, access_token)
                        print 'DELETE request url : %s' % delete_url

                        delete_info = requests.delete(delete_url).json()

                        if delete_info['meta']['code'] == 200:
                            print 'Comment successfully deleted!'
                        else:
                            print 'Could not delete the comment'

            else:
                print 'No comments found'
        else:
            print 'Status code other than 200 received!'
    except Exception as e:
        print e
        print 'Exception in comment deletion'
Ejemplo n.º 5
0
Archivo: views.py Proyecto: asmcos/jeap
def display_p(p_name,id):
    if request.method == 'POST':
        if require_login():
            return redirect(url_for(login))
        form = CommForm()
        flag = form.validate(request.params)
        if flag:
            co = comments(**form.data)
            co.username = request.user.username
            co.comm_objs = p_name
            co.save()
    pd = mdeps.filter(mdeps.c.d_name==p_name)
    cd = mdeps.filter(mdeps.c.d_parent_name==p_name)
    p = mpoints.get(mpoints.c.p_name == p_name)
    if not p:
        return redirect('/points/add_p/%s' % p_name)
    comm = comments.filter(comments.c.comm_objs==p_name)
    form = CommForm()
    return {'p':p,'pd':pd,'cd':cd,'comm':comm,'form':form}