Exemple #1
0
def create_results_file(q, max_links=2):
    s = AuthoritativeResults(q)
    res = s.get_results(max_links)
    
    with codecs.open('/media/files/documents/heart_results.html','w', "utf-8") as f:
        
        l = [
            (d['link'], d['title'], d['scores'], d['sum_terms'])
            for d in res
            ]
        
        s_s = '<html>\n<head>\n</head>\n<body>\n'
        s_m = ''
        s_f = '</body>\n</html>'
        n = 1
        for link in l:
            s_m += """<h4><a href="%(link)s">%(n)s - %(title)s</a></h4>\n
                        <p>Scores: %(scores)s</p>\n""" % {
                                                        'n': n,
                                                        'link': link[0],
                                                        'title': link[1],
                                                        'scores': link[2]
                                                        }
            n += 1
        s = s_s + s_m + s_f
        f.write(s)
Exemple #2
0
 def get(self, request, *args, **kwargs):
     q = request.GET.get('q')
     k = request.GET.get('k')
     
     max_links = 4 # Limiting the number of links
     
     if k == 'wait': # Send results to browser
         s = AuthoritativeResults(q)
         res = s.get_results(max_links)
         
         l = [
             (d['link'], d['title'], d['scores'], d['sum_words'],
             d['sum_unique_words'], d['sum_terms'])
             for d in res
             ]
         
         return render_to_response('results.html', {'list_d':l})
     
     elif k == 'create': # Create file with results
         tasks.create_results_file.delay(q, max_links)
         return render_to_response('wait.html')