예제 #1
0
def add_numbers():

    a = request.args.get('a', 0, type=str)
    summarizer = Summarizer()
    # a = u"http://www.asriran.com/fa/news/332468/%D9%BE%DB%8C%D8%A7%D9%85-%D8%B3%DB%8C%D8%AF-%D9%85%D8%AD%D9%85%D8%AF-%D8%AE%D8%A7%D8%AA%D9%85%DB%8C-%D8%A8%D9%87-%DA%A9%D9%86%DA%AF%D8%B1%D9%87-%D9%8A%DA%A9-%D8%AD%D8%B2%D8%A8"
    page = Fetch(a)
    if page.service == 'iransamane':
        service = IranSamane(page.page)
    elif page.service == 'news-studio':
        service = NewsStudio(page.page)
    else:
        service = Service(page.page)

    print "fetching content"
    content = service.fetch_content()
    # print content
    print "end fetching"
    summarized = summarizer.summarize(content)
    print "end summarize"
    res = {
        'summarized': summarized,
        'title': service.fetch_title(),
        'tags': service.fetch_tags(),
        'image': service.fetch_image(),
    }

    # For log
    log = (datetime.datetime.now(), res['title'], content, pickle.dumps(summarized)) 
    query_db('INSERT INTO log (submitted_time, title, source, summarized_text) VALUES (?,?,?,?)', log)
    # 
    return jsonify(result=res)
예제 #2
0
파일: tests.py 프로젝트: abdolhosein/moujez
    try:
        summarizer = Summarizer()
        page = Fetch(i["href"])
        if page.service == 'iransamane':
            service = IranSamane(page.page)
        elif page.service == 'news-studio':
            service = NewsStudio(page.page)
        else:
            service = Service(page.page)

        content = service.fetch_content()
        summarized = summarizer.summarize(content)
        print "end summarize"
        res = {
            'summarized': summarized,
            'title': service.fetch_title(),
            'tags': service.fetch_tags(),
            'image': service.fetch_image(),
        }

        # For log
        sums = ""
        for i in summarized:
            sums += i
        koft =  len(sums) / len(content) * 100.0
        print koft
        log = (datetime.datetime.now(), res['title'], content, sums, len(content), len(sums), koft) 
        cursor.execute('INSERT INTO log (submitted_time, title, source, summarized_text, source_len, summarized_text_len, darsad) VALUES (?,?,?,?,?,?,?)', log)
        conn.commit()
    except:
        print "nashooood", c
예제 #3
0
    try:
        summarizer = Summarizer()
        page = Fetch(i["href"])
        if page.service == 'iransamane':
            service = IranSamane(page.page)
        elif page.service == 'news-studio':
            service = NewsStudio(page.page)
        else:
            service = Service(page.page)

        content = service.fetch_content()
        summarized = summarizer.summarize(content)
        print "end summarize"
        res = {
            'summarized': summarized,
            'title': service.fetch_title(),
            'tags': service.fetch_tags(),
            'image': service.fetch_image(),
        }

        # For log
        sums = ""
        for i in summarized:
            sums += i
        koft = len(sums) / len(content) * 100.0
        print koft
        log = (datetime.datetime.now(), res['title'], content, sums,
               len(content), len(sums), koft)
        cursor.execute(
            'INSERT INTO log (submitted_time, title, source, summarized_text, source_len, summarized_text_len, darsad) VALUES (?,?,?,?,?,?,?)',
            log)