def queryjianshu(self, num): url = self.server # 添加headers headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0' } html = requests.get(url, headers=headers).text soup = BeautifulSoup(html, 'lxml') # 根据条件筛选元素 divs = soup.find_all('span', class_="time") completed = False for tex in divs: # 寻找写作的时间,如果有今天时间就日更完成,不然提醒 writertime = tex.get('data-shared-at')[0:10] ntime = time.strftime("%Y-%m-%d", time.localtime()) if writertime == ntime: completed = True # completed判断是否写作完成了 if completed: self.janshucom = True s = '很好完成日更了' SendMail().accesssendmail(s) else: s = '无日更!!!!第' + str(num) + '次提醒' print(s) SendMail().accesssendmail(s)
class Parser: sendMail = SendMail.SendMail() msg = '' # msg = jsondata(sender, receiver, subject), HTML id, def setMsg(self, msg): self.msg = msg def parsing(self): params = self.msg.decode('utf-8') dictParams = json.loads(params) self.sendMail.setMailInfo(dictParams['htmlId'], dictParams['verifyingKey'], dictParams['sender'], dictParams['receiver'], dictParams['subject']) #edit html edit = editHTML.EditHTML() edit.setTemplateId(dictParams['htmlId']) edit.setVerifyKey(dictParams['verifyingKey']) edit.editHTML() self.sendMail.setMsg("hello") #send self.sendMail.sendMail()
def task(start, end): global counter sql = MySQLdb.connect("localhost", "root", "****", "www", charset="utf8") cur = sql.cursor() #end=start+50 for x in range(start, end): try: print counter handleOnePage(getPage(str(x), "16-17-3"), sql, cur) counter = counter + 1 except Exception as e: print e SendMail.SendMail("*****@*****.**", "Inform", str(start) + "-" + str(end) + " Finished!") cur.close() sql.close()
'Samples':[ 'WW-LO', 'WZ', 'ZZ', 'TTToSemiLeptonic', '_WpWmJJ_', '_WpWpJJ_', 'ST_t', 'TTW', 'TTZ', 'WJetsToLN', 'DYJets', 'QCD', ], } job=latinoTransfer() job.Production=dic['Production'] job.Step=dic['Step'] for s in dic['Samples']: this_list=job.MakeList(Sample=s) job.Run(this_list) from SendMail import * SendMail(GetScriptName())
subjectPostPend = "" #print(a.checkDict) try: for k, v in a.checkDict.items(): for item, itemData in v['results'].items(): count = count + 1 mail = mail + "<p style=\"font-size:%spx\">Alarm on item %s while \"%s\"</p>\n" % ( fontsize, item, v['name']) mail = mail + "<p style=\"color:#770000; font-size:%spx\">%s</p>\n" % ( fontsize - 3, pprint(itemData)) mail = mail + "<table>" for itemDataK, ItemDataV in itemData.items(): mail = mail + "<tr><td style=\"font-size:%spx\">%s</td<><td style=\"font-size:%spx\">%s</td></tr>" % ( fontsize - 3, itemDataK, fontsize - 3, ItemDataV) mail = mail + "</table>" subjectPostPend = " | %s" % v['name'] except: pass mail = mail + "</body></html>\n" if count >= 1: from SendMail import * smtpResp = SendMail( config.toAddrs, mail, "Alarm from %s %s" % (socket.gethostname(), subjectPostPend)) #for to in config.toAddrs: # print("[a] mail to %s from %s"%(to,config.toAddrs)) # smtpResp = SendMail(to,mail,"Alarm from RedELK") print("[A] we had %s alarm lines" % count) else: print("[ ] no alarms")
import SendMail as sm sender = "*****@*****.**" sender_password = "******" receiver = "you@your_provider.com" subject = "the subject" message = "the message" mail_ = sm.SendMail(sender, sender_password, receiver, subject, message) mail_.SendEmail()
#normal { font-family: Tahoma, Geneva, sans-serif; font-size: 16px; line-height: 24px; } </style> </head><body> """ count = 0 #print(a.checkDict) try: for k, v in a.checkDict.items(): for item, itemData in v['results'].items(): count = count + 1 mail = mail + "<p style=\"font-size:%spx\">Alarm on item %s while \"%s\"</p>\n" % ( fontsize, item, v['name']) mail = mail + "<p style=\"color:#770000; font-size:%spx\">%s</p>\n" % ( fontsize - 3, pprint(itemData)) except: pass mail = mail + "</body></html>\n" if count >= 1: from SendMail import * smtpResp = SendMail(config.toAddrs, mail, "Alarm from %s" % socket.gethostname()) #for to in config.toAddrs: # print("[a] mail to %s from %s"%(to,config.toAddrs)) # smtpResp = SendMail(to,mail,"Alarm from RedELK") print("[A] we had %s alarm lines" % count) else: print("[ ] no alarms")
def search(idex, row): browser.get('https://weixin.sogou.com/') browser.save_screenshot(pv.poto_dir + "1.png") # 定位输入框 input_box = browser.find_element_by_id('query') # 输入内容: input_box.send_keys(row['公众号']) browser.save_screenshot(pv.poto_dir + "2.png") wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, '#searchForm > div > input.swz2'))).click() sleep(5) browser.save_screenshot(pv.poto_dir + "3.png") print("2" * 100) for i in range(8): # 需要优化为根据出现条目循环 try: tar = '#sogou_vr_11002301_box_{}'.format(i) browser.save_screenshot(pv.poto_dir + "4.png") wx_en = browser.find_element_by_css_selector( tar + ' > div > div.txt-box > p.tit > a > em').text wx_en_1 = browser.find_element_by_css_selector( tar + ' > div > div.txt-box > p.tit > a ').text wx_hao = browser.find_element_by_css_selector( tar + ' > div > div.txt-box > p.info > label').text print("0--" * 10, wx_en, wx_en_1, wx_hao) except: wx_en, wx_en_1, wx_hao = '', '', '' # print("第{}条不存在".format(i+1)) # 文章不存在 try: wx_file = browser.find_element( By.CSS_SELECTOR, tar + ' > dl:nth-child(3) > dd > a > em').text except: wx_file = '' # print("网络访问不了,或者被屏蔽!") try: wx_file_1 = browser.find_element( By.CSS_SELECTOR, tar + ' > dl:nth-child(3) > dd > a ').text except: wx_file_1 = '' try: wx_time = browser.find_element( By.CSS_SELECTOR, tar + ' > dl:nth-child(3) > dd > span').text except: wx_time = '' # print(wx_hao) # print(wx_en + wx_en_1, wx_hao, wx_file + wx_file_1, wx_time) if wx_hao in WX['微信号'].values.tolist( ) and row['最新文章'] != wx_file + wx_file_1 and wx_time != '': try: wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, tar + ' > dl:nth-child(3) > dd > a'))).click() except: print("文章不存在!") # 获取打开的多个窗口句柄 windows = browser.window_handles # 切换到当前最新打开的窗口 browser.switch_to.window(windows[-1]) sleep(2) scroll_width = browser.execute_script( 'return document.body.parentNode.scrollWidth') # 设置宽高,便于截图 scroll_height = browser.execute_script( 'return document.body.parentNode.scrollHeight') for num in range(0, 8000, 10): # 缓慢滚动鼠标 js = 'window.scrollTo(0,{})'.format(num) browser.execute_script(js) if num % 500 == 0: sleep(2) # print(num, scroll_height) if scroll_height < num: # 滚动到底部退出 break name = wx_file + wx_file_1 + date.today().strftime("%Y-%m-%d") name = validateTitle(name) file = pv.poto_dir + "{}.png".format(name) # pd. print(name, wx_file, wx_file_1, date.today().strftime("%Y-%m-%d")) browser.set_window_size(scroll_width, scroll_height) browser.get_screenshot_as_file(file) row['最新文章'] = wx_file + wx_file_1 WX.iloc[idex] = pd.Series(row) WX_h = pd.read_excel(pv.file, sheet_name='history') WX_h = WX_h.append([{ '序号': len(WX_h) + 1, '公众号': row['公众号'], '微信号': row['微信号'], '最新文章': wx_en + wx_file + wx_file_1, '发表时间': time.strftime("%Y-%m-%d %H:%M:%S") }], ignore_index=True) writer = pd.ExcelWriter(pv.file) WX.to_excel(writer, "Sheet1", index=False) WX_h.to_excel(writer, "history", index=False) writer.save() # 会覆盖sheet表 # WX.to_excel('E:/TEMP/untitled111111/WX_File.xlsx', sheet_name='history', index=False) # WX.to_excel('E:/TEMP/untitled111111/WX_File.xlsx', sheet_name='Sheet1', index=False) # 发送邮件 # send_m(wx_en + "__" + wx_file + wx_file_1, file, row['Email']) title = wx_en + "__" + wx_file + wx_file_1 content = ''' <p>{}</p> <p><img src="cid:image1"></p> '''.format(title) email = str(row['Email']) if email == '' or "@" not in email: recv = pv.jieshou else: recv = email.split(',') m = SendMail.SendMail(username=pv.fasong, passwd=pv.key, title=title, recv=recv, content=content, image=file) m.send_mail() browser.close() # 关闭当前窗口 browser.switch_to.window(windows[0]) # 切换回窗口A
import SendMail import private as pv m = SendMail.SendMail(username=pv.fasong, passwd=pv.key, title="Test2020", recv=["*****@*****.**"], content = ''' <h5>这是一份测试邮件,!!!!</h5> <p>图片展示:</p> <p><img src="cid:image1"></p> ''', file='E:/TEMP/untitled111111/WX_File.xlsx', image='E:/TEMP/untitled111111/test.png') m.send_mail()