def getAllContent(self): sqlHelper = MySQLHelper('101.1.16.50','s559384db0','995y455y','s559384db0'); if type(self.urls) == list: for urlItem in self.urls: sqlStr = "select infoId from tblJobInfo where bbsId = "+ urlItem["bbsId"] + " and " + self.timeCondition temptInfoList = sqlHelper.queryAll(sqlStr) self.existInfoIdList = [] for infoDic in temptInfoList: self.existInfoIdList.append(infoDic["infoId"]) self.getContent(urlItem) else: sqlStr = "select infoId from tblJobInfo where bbsId = "+ str(self.urls["bbsId"]) + " and " + self.timeCondition temptInfoList = sqlHelper.queryAll(sqlStr) self.existInfoIdList = [] for infoDic in temptInfoList: self.existInfoIdList.append(infoDic["infoId"]) self.getContent(self.urls)
def getContact(self): contactList = [] sqlHelper = MySQLHelper('101.1.16.46','s559384db0','995y455y','s559384db0'); dbUserList = sqlHelper.queryAll("SELECT fakeId FROM tblUserInfo ") dbFakeIdList = [] for user in dbUserList: dbFakeIdList.append(user["fakeId"]) print dbFakeIdList print self.fakeIdList[0:2] for fakeId in self.fakeIdList: if fakeId not in dbFakeIdList: print fakeId self.pushWelcomeMsg(fakeId) userContact = self.getUserInfo(fakeId) encoding = chardet.detect(userContact)['encoding'] if userContact != 'utf-8': userContact = userContact.decode(encoding, 'replace').encode('utf-8') contactList.append(userContact) for value in contactList: insertValue = eval(value) del insertValue["Groups"] sqlHelper.insert("tblUserInfo", insertValue)
class AutoSendMsg(): def __init__(self, userName, pwd): self.userName = userName self.pwd = pwd self.isNotSendMsg = False self.msgUrl ='https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&lang=zh_CN' def getRequestInfo(self): wecharInfo = WechartToken(self.userName, self.pwd) self.headers = { 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'Referer':'https://mp.weixin.qq.com/cgi-bin/singlemsgpage', 'User-Agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31', 'X-Requested-With':'XMLHttpRequest' } self.cookies = dict(wecharInfo.cookie) self.token = wecharInfo.token def getInfoContent(self): self.sqlHelper = MySQLHelper('101.1.16.50','s559384db0','995y455y','s559384db0'); startTimeStamp = datetime.now() + timedelta(hours=-7) endTimeStamp = datetime.now() + timedelta(hours=1) startTime = datetime(startTimeStamp.year, startTimeStamp.month, startTimeStamp.day, startTimeStamp.hour).strftime("%Y-%m-%d %H:%M:%S") endTime = datetime(endTimeStamp.year, endTimeStamp.month, endTimeStamp.day, endTimeStamp.hour).strftime("%Y-%m-%d %H:%M:%S") timeCondition = "saveTime between '" + startTime + "' and '" + endTime + "'" sqlStr = "select * from tblJobInfo where " + timeCondition + " order by id desc limit 24" print sqlStr temptInfoList = self.sqlHelper.queryAll(sqlStr) if len(temptInfoList) == 0: self.isNotSendMsg = True return resultContent = "" for index, value in enumerate(temptInfoList): if index % 2 == 1: contentUrl = "http://campus4me.net/showMsgContent.php?msgId=" + value["id"] resultContent += "名称:" + value["title"] + "<a href=\"" + contentUrl +"\">[查看详情]</a>\n\n" self.resultContent = resultContent + "亲,记得回复‘h’显示更多帮助哦!!" print self.resultContent def sendMsg(self): sqlUserFakeId = "select fakeId from tblUserInfo" self.getInfoContent() print "isNotSendMsg: " + str(self.isNotSendMsg) if self.isNotSendMsg == True: return self.getRequestInfo() fakeIdList = self.sqlHelper.queryAll(sqlUserFakeId) sendMsg = { 'type':1, 'error':False, 'tofakeid':'', 'token':self.token, 'content': self.resultContent, 'ajax':1 } print sendMsg sendedUser = [] hasSendedUser = [] print len(hasSendedUser) for index, infoItem in enumerate(fakeIdList): if infoItem["fakeId"] != "31164395" and infoItem["fakeId"] not in hasSendedUser: #if infoItem["fakeId"] == "520181815": sendMsg.update({'tofakeid':infoItem["fakeId"]}) sendedUser.append(infoItem["fakeId"]) print sendedUser responseMsg = requests.post(self.msgUrl, data = sendMsg, headers = self.headers,cookies = self.cookies); print responseMsg.content print sendedUser