コード例 #1
0
 def save_one_news(cls, url, db_name, table_name):
     news_info = WangyiNewsExtractor.news_info_by_url(url)
     if news_info:
         MysqlHelper.insert_news_mid(db_name=db_name,
                                     table_name=table_name,
                                     news_title=news_info["title"],
                                     pub_time=news_info["time"],
                                     content=news_info["content"],
                                     news_src="网易",
                                     news_link=news_info["url"],
                                     category=news_info["category"],
                                     topic='',
                                     summary='',
                                     polarity=news_info["polarity"])
コード例 #2
0
 def save_old_news_day(cls, date):
     news_list = SinaNewsBrief.fetch_news_by_day(date)
     print 'news_list_get'
     count = 0
     for news_block in news_list:
         try:
             news_url = news_block['url']
             news_content = Html2Article.url2article(news_url)
             page_content = requests.get(news_url).content
             news_keyword = SinaNewsExtract.extract_keywords(page_content)
             polarity = SentiCalc.score_calc(news_block["title"])
             MysqlHelper.insert_news_mid('sina_news', 'sina_mid', news_block['title'], news_block['time'], news_content, '新浪', news_block['url'], news_block['category'], news_keyword, '', polarity=str(polarity))
             print count, polarity, news_block['title']
             count += 1
         except Exception, e:
             print e