Пример #1
0
def topic_ajax_stat():
    if request.method == 'GET':
        keyword = request.args.get('keyword', "")
        keyuser = request.args.get('keyuser', "")
        beg_time = int(request.args.get('beg_time', ""))
        end_time = int(request.args.get('end_time', ""))
    
        fields_list = ['text', 'timestamp','reposts_count','comments_count','user', 'terms', '_id','retweeted_status','bmiddle_pic','geo','source','attitudes_count'] 
        count, get_results = search_weibo.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)

        topic_info = calculate(get_results())

        topic_persistent_count = topic_info['topic_index']['persistent_index']
        topic_sudden_count = topic_info['topic_index']['sudden_index']
        topic_coverage_count = topic_info['topic_index']['coverage_index']
        topic_media_count = topic_info['topic_index']['media_index']
        topic_leader_count = topic_info['topic_index']['leader_index']

        return render_template('propagate/ajax/topic_stat.html',
                                topic_persistent_count = topic_persistent_count,
                                topic_sudden_count = topic_sudden_count,
                                topic_coverage_count = topic_coverage_count,
                                topic_media_count = topic_media_count,
                                topic_leader_count = topic_leader_count
        )
Пример #2
0
def topic_ajax_weibos():
    if request.method == "GET":
        keyword = request.args.get('keyword', "")
        keyuser = request.args.get('keyuser', "")
        beg_time = int(request.args.get('beg_time', ""))
        end_time = int(request.args.get('end_time', ""))
    
        fields_list = ['text', 'timestamp','reposts_count','comments_count','user', 'terms', '_id','retweeted_status','bmiddle_pic','geo','source','attitudes_count'] 
        count, get_results = search_weibo.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)

        topic_info = calculate(get_results())
        blog_rel_list = topic_info['topic_rel_blog'][:5]

        return render_template('propagate/ajax/topic_weibos.html', blog_rel_list= blog_rel_list)
Пример #3
0
def main():
    topics = _topic_not_calc()
    if topics and len(topics):
    	topic = topics[0]

        start_ts = topic.start
        end_ts = topic.end
        db_date = topic.db_date
        topicname = topic.topic
        print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), topicname.encode('utf-8'), 'start'
        _update_topic_status2Computing(topicname, start_ts, end_ts, db_date)
        result  = calculate(topicname,start_ts,end_ts)
        print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), topicname.encode('utf-8'), result
        _update_topic_status2Completed(topicname, start_ts, end_ts, db_date)
Пример #4
0
def topic_ajax_spatial():
    if request.method == "GET":
        return render_template('propagate/ajax/topic_spatial.html')
    else:
        keyword = request.form.get('keyword', "")
        keyuser = request.form.get('keyuser', "")
        beg_time = int(request.form.get('beg_time', ""))
        end_time = int(request.form.get('end_time', ""))
    
        fields_list = ['text', 'timestamp','reposts_count','comments_count','user', 'terms', '_id','retweeted_status','bmiddle_pic','geo','source','attitudes_count'] 
        count, get_results = search_weibo.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)

        topic_info = calculate(get_results())
        topic_area_list = topic_info['geo']

        return json.dumps({'map_data': topic_area_list})
Пример #5
0
def topic_ajax_trend():
    if request.method == "GET":
        return render_template('propagate/ajax/topic_trend.html')
    else:
        keyword = request.form.get('keyword', "")
        keyuser = request.form.get('keyuser', "")
        beg_time = int(request.form.get('beg_time', ""))
        end_time = int(request.form.get('end_time', ""))
    
        fields_list = ['text', 'timestamp','reposts_count','comments_count','user', 'terms', '_id','retweeted_status','bmiddle_pic','geo','source','attitudes_count'] 
        count, get_results = search_weibo.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)

        topic_info = calculate(get_results())
        perday_blog_count = topic_info['perday_count_list']
        date_list = topic_info['date_list']
        date_list = [int(time.mktime(d.timetuple()))*1000 for d in date_list]

        return json.dumps({'perday_blog_count': zip(date_list, perday_blog_count)})
Пример #6
0
def showresult_by_topic():
    # get the input context
    keyword = request.args.get('keyword', "")
    keyuser = request.args.get('keyuser', "")
    beg_time = request.args.get('beg_time', "")
    end_time = request.args.get('end_time', "")
    test = request.args.get('test', 'None')
    
    keyword = keyword.strip('@\r\n\t')
    keyuser = keyuser.strip('@\r\n\t')
    beg_time = beg_time.strip('@\r\n\t')
    end_time = end_time.strip('@\r\n\t')

    return_beg_str = beg_time
    return_end_str = end_time
    keyuser_str = keyuser
    
    if keyword == "":
        flash(u'关键字(词)不能为空')
        field_topics = getFieldTopics()
        status_hot = getHotStatus()
        return render_template('propagate/search.html',field_topics = field_topics,status_hot = status_hot)
    if keyuser == "":
        keyuser_str = u'无'
    if beg_time == "":
        beg_time = calendar.timegm(datetime(2013, 1, 1).timetuple())
        return_beg_str = '2013-01-01'
    else:
        beg_time = datetime.strptime(beg_time,"%Y-%m-%d")
        beg_time_year = int(beg_time.year)
        beg_time_month = int(beg_time.month)
        beg_time_day = int(beg_time.day)
        beg_time = calendar.timegm(datetime(beg_time_year,beg_time_month,beg_time_day).timetuple())
    if end_time == "":
        end_time = calendar.timegm(datetime(2013, 1, 7).timetuple())
        return_end_str = '2013-01-07'
    else:
        end_time = datetime.strptime(end_time,"%Y-%m-%d")
        end_time_year = int(end_time.year)
        end_time_month = int(end_time.month)
        end_time_day = int(end_time.day)
        end_time = calendar.timegm(datetime(end_time_year,end_time_month,end_time_day).timetuple())
        
    fields_list = ['text', 'timestamp','reposts_count','comments_count','user', 'terms', '_id','retweeted_status','bmiddle_pic','geo','source','attitudes_count'] 
    if test == 'None':
        count, get_results = search_weibo.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)
    else:
        count, get_results = search_weibo_test.search(query={'text': [u'%s'%keyword], 'timestamp': {'$gt': beg_time, '$lt': end_time}}, sort_by=['timestamp'], fields=fields_list)        
    if count == 0:
        flash(u'您搜索的话题结果为空')
        field_topics = getFieldTopics()
        status_hot = getHotStatus()
        return render_template('propagate/search.html',field_topics = field_topics,status_hot = status_hot)
    else:
        print count
        topic_info = calculate(get_results())
        print 'ok'
        topic_ori_screen_name = topic_info['topic_poster']
        topic_img_url = topic_info['topic_url']
        topic_blog_count = topic_info['blogs_sum']
        topic_blog_ori_count = topic_info['topic_ori_blog_count']
        blog_ori_account = '%10.2f'%(float(topic_blog_ori_count)/topic_blog_count)
        topic_leader_count = topic_info['topic_index']['leader_index']
        topic_ori_date = topic_info['topic_post_date']

        return json.dumps({'topic_profile_image_url': topic_img_url[0]})
        '''