資源簡介
用python寫的微博情感分析,自然語言處理,情感分類,請放心下載
代碼片段和文件信息
#?-*-?coding:utf-8?-*-
import?sys
import?MySQLdb
import?ConfigParser
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
class?GetConnect(object):
def?__init__(self):
self.host?=?None
self.user?=?None
self.passwd?=?None
self.port?=?None
self.db?=?None
self.charset?=?None
self.use_unicode?=?None
self.initParams()
self.conn?=?None
self.cursor?=?None
self.initDb()
def?initParams(self):
‘從配置文件中初始化參數變量‘
cf?=?ConfigParser.ConfigParser()
cf.read(‘config.ini‘)
self.host?=?cf.get(‘db‘?‘host‘)
self.port?=?int(cf.get(‘db‘?‘port‘))
self.user?=?cf.get(‘db‘?‘user‘)
self.passwd?=?cf.get(‘db‘?‘passwd‘)
self.db?=?cf.get(‘db‘?‘db‘)
self.charset?=?cf.get(‘db‘?‘charset‘)
self.use_unicode?=?cf.get(‘db‘?‘use_unicode‘)
def?initDb(self):
try:
self.conn?=?MySQLdb.connect(host=self.host?port=self.port?user=self.user?\
passwd=self.passwd?db=self.db?charset=self.charset?use_unicode=self.use_unicode)
self.cursor?=?self.conn.cursor()
except?MySQLdb.Error?e:
print?‘Mysql?Error?%d:?%s‘?%?(e.args[0]?e.args[1])
print?‘Failed?to?connect?to?database!?Please?check?your?config?file?and?confirm?your?database?is?open‘
sys.exit(-1)
print?‘Success?connect?database‘
def?getCount(self?sql):
count?=?self.cursor.execute(sql)
return?count
def?getData(self?sql):
count?=?self.cursor.execute(sql)
print?‘There?has?%d?rows?record‘?%?count
if?count?!=?0:
results?=?self.cursor.fetchall()
return?results
else:
return?None
def?executeDB(self?sql):
try:
self.cursor.execute(sql)
self.conn.commit()
except?Exception?e:
print?“Insert?Error“
print?‘Mysql?Error?%d:?%s‘?%?(e.args[0]?e.args[1])
print?‘Success?execute?sql‘
def?closeResource(self):
if?self.cursor:
self.cursor.close()
if?self.conn:
self.conn.close()
def?main():
pass
if?__name__?==?‘__main__‘:
main()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\
?????文件??????????23??2017-06-30?15:50??weibo_sentiment_analysis\.git\HEAD
?????文件?????????322??2017-06-30?15:50??weibo_sentiment_analysis\.git\config
?????文件??????????73??2017-06-30?15:50??weibo_sentiment_analysis\.git\desc
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\
?????文件?????????478??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\applypatch-msg.sample
?????文件?????????896??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\commit-msg.sample
?????文件?????????189??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\post-update.sample
?????文件?????????424??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\pre-applypatch.sample
?????文件????????1642??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\pre-commit.sample
?????文件????????1348??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\pre-push.sample
?????文件????????4951??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\pre-reba
?????文件?????????544??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\pre-receive.sample
?????文件????????1239??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\prepare-commit-msg.sample
?????文件????????3610??2017-06-30?15:50??weibo_sentiment_analysis\.git\hooks\update.sample
?????文件????????8621??2017-06-30?15:50??weibo_sentiment_analysis\.git\index
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\info\
?????文件?????????240??2017-06-30?15:50??weibo_sentiment_analysis\.git\info\exclude
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\
?????文件?????????197??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\HEAD
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\heads\
?????文件?????????197??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\heads\master
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\remotes\
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\remotes\origin\
?????文件?????????197??2017-06-30?15:50??weibo_sentiment_analysis\.git\logs\refs\remotes\origin\HEAD
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\ob
?????目錄???????????0??2018-01-03?18:47??weibo_sentiment_analysis\.git\ob
?????目錄???????????0??2017-06-30?15:50??weibo_sentiment_analysis\.git\ob
?????文件????????4824??2017-06-30?15:50??weibo_sentiment_analysis\.git\ob
............此處省略94個文件信息
評論
共有 條評論