Beispiel #1
0
def mark(request, flag):
    
    id = request.GET.get('post', None)
    feed = request.GET.get('feed', None)
    category = request.GET.get('category') 
    tag = request.GET.get('tag') or None
    
    try:
        if feed:
           posts = Post.objects.filter(feed=feed)
        else:
           posts = Post.objects.filter(id=id)
    except Post.DoesNotExist:
        return HttpResponseRedirect('/')
    
    bayes = Brain.objects.get(user=request.user) #login required
    brain = Bayes()
    brain.loads(base64.decodestring(bayes.data))
    
    if flag in ('read', 'unread'):
        flag = flag == 'read'
        posts.update(read=flag) 
    else:
        for post in posts:
            text = "%s %s %s" % (post.title, post.author, post.summary)
            t1 = Tag.objects.get(id=flag)
            if t1 in post.tags.all() and not feed:
                post.tags.remove(t1) 
                brain.untrain(t1.name, text)
            else:
                post.tags.add(t1)
                brain.train(t1.name, text)
            post.save()    
        
    bayes.data = base64.encodestring(brain.saves())
    bayes.save()
        
    if category:
       return HttpResponseRedirect('/?category=%s' % category)
    elif feed:
       return HttpResponseRedirect('/?feed=%s' % feed)
    elif tag:
       return HttpResponseRedirect('/?tag=%s' % tag)
    else:
       return HttpResponseRedirect('/')
Beispiel #2
0
def read(request, id):
    try:
        post = Post.objects.get(id=id)
        post.read = True
        post.save()

        try:
            bayes = Brain.objects.get(user=request.user) #login required
            brain = Bayes()
            brain.loads(base64.decodestring(bayes.data))
            text = post.title + ' ' + post.author + post.summary
            brain.train('Interesting', text)        
            bayes.data = base64.encodestring(brain.saves())
            bayes.save()
        except Exception, e:
            print "Couldn't train %s because %s" % (post.title, e)

        return HttpResponseRedirect(post.link)
Beispiel #3
0
                        "user": user,
                        "title": title,
                        "author": author,
                        "description": description,
                        "summary": summary,
                        "content": content,
                        "link": link,
                    },
                )

                # Autotagging new posts
                if created:
                    try:
                        bayes = Brain.objects.get(user=user)
                        brain = Bayes()
                        brain.loads(base64.decodestring(bayes.data))
                        text = "%s %s %s" % (title, author, summary)
                        guess = brain.guess(text)
                        for t in guess:
                            if t[1] > 0.75:
                                tag = Tag.objects.filter(user=user).filter(name=t[0])
                                if tag:
                                    print "Autotagging %s as %s" % (title, t[0])
                                    post.tags.add(tag[0].id)
                    except Exception, e:
                        print "Problem autotagging %s, Exception says: %s" % (title, e)

                dtMax = max(dtMax, post.dt_published)
                post.current = True
                if created and isDuplicate(post.title):
                    print "Skipping duplicate or old news"