def _topics_names(): results = [] topics = _all_topics(True) for topic in topics: results.append(topic.topic) return results
def maintain_topic_sentiment(xapian_search_weibo, start_ts, end_ts): topics = _all_topics(iscustom=True) during = end_ts - start_ts for topic in topics: topicname = topic.topic results = sentimentRealTime(xapian_search_weibo, end_ts, during, method='topic', calc='all', query=topicname)
def topics_customized(): if request.method == 'GET': #通过keyword获取topic以及对应的时间戳形成的序列 keyword = request.args.get('keyword',None) if keyword: topics = _search_topic(keyword,True) else: topics = _all_topics(True) topics_names = [] if topics: for topic in topics: db_date = time.strftime("%m月 %d日, %Y %H:%M:%S", time.localtime(topic.db_date)) datestr = ' 提交时间: ' + db_date # topics_names.append(topic.topic) topics_names.append([topic.topic, datestr]) return json.dumps(topics_names) else: #对topic进行操作---添加或者删除 operator = request.form.get('operator', 'add') topic = request.form.get('topic', '') if topic != '': if operator == 'add': status, item = _add_topic(topic) if operator == 'del': status, item = _drop_topic(topic) item = item.topic else: status, item = 'NoTopic', 'Null' return json.dumps({'status': status, 'item': item})
def _check_run_customize_topic(cron_start_ts, during=Fifteenminutes): '''定时执行定制话题表中iscusotom为True的话题数量、关键词、关键微博计算, 默认当前时间为2013年9月1日,0时0分0秒 ''' topics = _all_topics(True) for topic in topics: topicname = topic.topic '''
from topics import _all_topics SENTIMENT_TOPIC_KEYWORDS = "sentiment_topic_keywords" def _default_redis(host=REDIS_HOST, port=REDIS_PORT, db=0): return redis.StrictRedis(host, port, db) def _utf8_encode(s): if isinstance(s, str): return s else: return s.encode('utf-8') def _clear_keywords(r): r.delete(SENTIMENT_TOPIC_KEYWORDS) def _add_keyword(r, k): r.sadd(SENTIMENT_TOPIC_KEYWORDS, _utf8_encode(k)) if __name__ == '__main__': r = _default_redis() topics = _all_topics(True) _clear_keywords(r) for topic in topics: _add_keyword(r, topic.topic)