def plotMonthlyTrend(keywords, title, monthList): db = mysql(host, user, passwd, dbName) db.connect() allKeywordTrend = [] for k in keywords: allCount = [] for m in monthList: rows = db.getMonthlyKeywordCount(k, m) print rows count = 0 for r in rows: count += r[0] persent = count * 1.0 cc = db.getMonthlyTweetCount(m) if cc == 0: persent = 0.0 else: persent /= cc allCount.append(persent) allKeywordTrend.append(allCount) db.close() for p in allKeywordTrend: pylab.plot(range(1, len(p) + 1), p) pylab.title(title) pylab.legend(keywords) pylab.xlabel("month") pylab.ylabel("frequency of occurrence") pylab.show()
def plotMonthlyTrend(keywords, title, monthList): db = mysql(host, user, passwd, dbName) db.connect() allKeywordTrend = [] for k in keywords: allCount = [] for m in monthList: rows = db.getMonthlyKeywordCount(k, m) print rows count = 0 for r in rows: count += r[0] persent = count*1.0 cc = db.getMonthlyTweetCount(m) if cc == 0: persent = 0.0 else: persent /= cc allCount.append(persent) allKeywordTrend.append(allCount) db.close() for p in allKeywordTrend: pylab.plot(range(1, len(p)+1), p) pylab.title(title) pylab.legend(keywords) pylab.xlabel("month") pylab.ylabel("frequency of occurrence") pylab.show()
# 发送邮件 yag.send(users, subjecttitle, contents, file) # yag.send('*****@*****.**', '发送附件', contents, ["d://testresult.html"]) x = sendmail() # # 邮箱正文 contents = [ 'This is the body, and here is just text http://somedomain/image.png', 'You can find an audio file attached.', '/local/path/song.mp3' ] x.sendmail('*****@*****.**', '发送邮件', contents) # x.sendmailFile('*****@*****.**', '发送带附件的邮件', contents, ["D:/htmlOut2018-06-22.html"]) m = mysql() m.insertSql() # 成功的例子 # yag = yagmail.SMTP(user="******", password="******", host='smtp.163.com') # # # # 邮箱正文 # contents = ['This is the body, and here is just text http://somedomain/image.png', # 'You can find an audio file attached.', '/local/path/song.mp3'] # # # 发送邮件 # yag.send('*****@*****.**', 'subject', contents) # # #给多个用户发送邮件# # # 发送邮件
def saveMonthlyTweetCount(monthList): db = mysql(host, user, passwd, dbName) db.connect() for m in monthList: db.computeAndSaveMonthlyTweetCount(m) db.close()
def __init__(self): self.db = mysql() self.db.connect()
reload(sys) sys.setdefaultencoding('utf-8') def generateDateList(startYear, count): monthList = [] for y in xrange(count): for m in xrange(1, 13): pattern = "%d-%d-01" % (startYear + y, m) monthList.append(pattern) return monthList monthList = generateDateList(2006, 9) for m in monthList: ana = analyser() db = mysql(host, user, passwd, dbName) db.connect() print "processing %s data..." % m for r in db.getMonthlyData(m): if (type(r[0]) == type(u' ')): ana.addAnalysisSentence(r[0]) for k in ana.wordRate.keys(): try: db.insertKeyword2DB(k, str(ana.wordRate[k]), m) except: continue db.close()
def __init__(self): self.c = mysql() return
import MySQLdb import io reload(sys) sys.setdefaultencoding('utf-8') def generateDateList(startYear, count): monthList = [] for y in xrange(count): for m in xrange(1, 13): pattern = "%d-%d-01" % (startYear+y, m) monthList.append(pattern) return monthList monthList = generateDateList(2006, 9) for m in monthList: ana = analyser() db = mysql(host, user, passwd, dbName) db.connect() print "processing %s data..." % m for r in db.getMonthlyData(m): if (type(r[0]) == type(u' ')): ana.addAnalysisSentence(r[0]) for k in ana.wordRate.keys(): try: db.insertKeyword2DB(k, str(ana.wordRate[k]), m) except: continue db.close()