def get(self): userlist=user_func.getUserList() for user in userlist: updateownlist = event_func.getUpdatedEventListByOwner(user.key.id()) sendEmail(updateownlist, user, "Event world: The events you created have update") updatevotelist = event_func.getUpdatedEventListByVoter(user.key.id()) sendEmail(updatevotelist, user, "Event world: The events you joined have update")
def notifySubscribe(self, toAdd, mailContent): subject = self.Subject %(self.blogType) _plainText = _htmlText = '<br><br>'.join(mailContent) _tmpfile = 'latest_%s.html' %(self.blogType) contentfile = open(_tmpfile, 'w') contentfile.write(_htmlText) sendEmail(self.authInfo, self.fromAdd, toAdd, subject, _plainText, _htmlText, 'utf-8')
def autoGet(cursor,f,num_book_init): t=0 num_book=num_book_init while num_book<20000 or t<30: num_book = num_book +1 t=once(cursor,num_book,t) set(f,num_book) delayTime_Random() pass sendmail.sendEmail('raspberry stop',"work is stop \n and the last num is : "+str(num_book)) pass
def process_text_step(message): try: templ['text'] = message.text sendmail.sendEmail(templ['lg'], templ['pw'], templ['rec'], templ['sb'], templ['text']) bot.send_chat_action(message.fr_user.id, 'typing') bot.send_message( message.from_user.id, 'Ваше сообщения отправлено на {}'.format(templ['rec'])) log(message) templ.clear() except Exception as e: bot.reply_to(message, 'ooooops') print(e)
def getPriceByDriverHeadless(): chrome_options = Options() chrome_options.add_argument('--headless') driver = webdriver.Chrome( "chromedriver", chrome_options=chrome_options) # open with Chrome driver.set_page_load_timeout(20) #(5) while True: config_dict = loadConfig() #dict 的迭代 for item in config_dict: try: print(timeStampToTime(time.time()), "open...", config_dict[item].get("URL")) driver.get(config_dict[item].get("URL")) print(timeStampToTime(time.time()), "open done") except Exception as e: print("Except:", e) print("加载页面太慢,直接停止加载,继续下一步操作") print(timeStampToTime(time.time()), config_dict[item].get("URL")) try: # 更好的方式 ele = driver.find_element_by_xpath( '//div[@class="dd"]/span[@class="p-price"]/span[contains(@class,"price")]' ) #print(ele) log.logInfo(driver.title + ": " + ele.text, log_file) if float(ele.text) < config_dict[item].get("ExpectedPrice"): #发送邮件提醒 print(driver.title) print(ele.text) sendmail.sendEmail( config_dict[item].get("Email", "*****@*****.**"), config_dict[item].get("URL") + " " + driver.title + ":" + ele.text) except Exception as e: print(e) log.logInfo("find_element_by_xpath error") time.sleep(30)
def passwd_send(request): form = PasswordForm(request.POST) if not form.is_valid(): request.session["error"] = form return redirect("/passwdForm") email = request.POST.get('email', "") try: from sendmail import sendEmail passwd = randomString(4) email_msg = u"위키독스 비밀번호가 초기화 되었습니다. 새 비밀번호:%s" % passwd sendEmail(email, u"위키독스 비빌번호 변경 알림", email_msg) u = User.objects.get(username=email) u.set_password(passwd) u.save() return passwdForm(request, successMsg=u"이메일로 재 성성된 비밀번호를 발송했습니다.") except: print traceback.format_exc() return passwdForm(request, errorMsg=u"이메일 송신이 실패했습니다.")
def generate_main(self): pro_data=self.get_project_data() title='Weekly Report for MySQL Databases NO.%s ' % (self.time) end_title='<b>more info:10.2.1.118/report<b>' body='<b>Summary:</b><br>' for item in command.cmd_report: cmd_sql=command.cmd_report[item] data=self.conn.fetchAll(cmd_sql)[0][0] body+=' %s: %s<br>'% (item,data) body+='<table><tr bgcolor="#E6EED5"><td>项目</td><td>部署结构</td><td>MySQL实例数量</td><td>服务器数量</td><td>最大数据量表</td><td>总数据量</td>\ <td>平均qps</td><td>MySQL运行时间</td><td>平均连接数</td><tr>[data]</table>' data='' alt =True for p in pro_data: color='bgcolor="#FFFFFF"' if alt else 'bgcolor="#E6EED5"' data +='<tr %s><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' %(color,p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]) alt=not alt body=body.replace('[data]', data) body+=end_title #print self.time sendEmail(mail_list,body,title) sql="insert into report_history(r_date,content) values('%s','%s')" % (self.time,title+body) self.conn.execute(sql)
def old_http_main(): html = getHtml(china_city_url) #print(html) #china_city = getCity(html) #统一成一个函数 china_city = getDataFromHtml(html, 'pro_city_data.*"国外"}]}', '{') # with open("china_city.txt","w+") as f: # # ensure 正常显示中文,而不是显示ASCII值。 # f.write(json.dumps(china_city,ensure_ascii=False, indent=4, separators=(',', ': '))) html = getHtml(haidilao_city_url) #shop_city = getHaidilaoCity(html) shop_city = getDataFromHtml(html, 'varallCities=.*gx"]', '[') #print(shop_city_data) # with open("shop_city.txt","w+") as f: # f.write(json.dumps(shop_city,ensure_ascii=False, indent=4, separators=(',', ': '))) #staticsShop(china_city,shop_city) staticsShop_thread(china_city, shop_city) #sendmail.sendEmail(["*****@*****.**"],'海底捞门店','Fighting',['result.xlsx','static_data.txt']) sendmail.sendEmail(email_list, '海底捞门店数据', 'Fighting', [execel_name])
def getPriceByDriver(): #注意驱动问题。一般最好和chrome版本一致。否则会出现莫名其妙的问题。 #这里用chrome已经是最新版本了。所以更新驱动。放置在当前目录。或者覆盖掉/usr/local/bin/chromedriver #webdriver.Chrome('./chromedriver') 具体路径,从具体路径去加载驱动。 #webdriver.Chrome("chromedriver") 会从默认的路径顺序去加载。 /usr/local/bin/chromedriver #webdriver.Chrome()<===> webdriver.Chrome("chromedriver") 看构造函数就清楚了 driver = webdriver.Chrome( "/usr/local/bin/chromedriver") # open with Chrome #driver.implicitly_wait(5) #设置等待时间都不起作用。什么显示 隐式时间都不行。 #因为driver.get 加载页面是同步阻塞的。因此有时候元素已经出来,但是还要完全等待完,没有必要,因此做超时处理。 driver.set_page_load_timeout(20) #(5) while True: config_dict = loadConfig() #dict 的迭代 for item in config_dict: # print(config_dict[item]) #locator = (By.XPATH, '//div[@class="dd"]/span[@class="p-price"]/span[contains(@class,"price")]') #locator = (By.ID,"banner-miaosha") #由于css中有多个属性,因此直接使用css selector 来获取 #使用xpath 也可以,要将带有空格也填入,不能只填入部分,否则找不到。 #但是基于jd网页上的class是根据商品的id合成的。因此直接填入不会通用。 # driver.find_element_by_xpath('//div[@class="dd"]/span[@class="p-price"]/span[@class="price J-p-6287165"]') #因此先找到父节点(缩小范围),再找下面那个带有price class 的节点。 #<span class="price J-p-6287165">329.00</span> #ele_p = driver.find_element_by_xpath('//div[@class="dd"]/span[@class="p-price"]') # ele_p.text ¥329.00 #ele = ele_p.find_element_by_css_selector('.price') #ele.text 329 try: print("open...") print(timeStampToTime(time.time()), config_dict[item].get("URL")) driver.get(config_dict[item].get("URL")) #不起作用 #WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located(locator)) print("open done") #driver.get() 是同步阻塞的。要等网页完全打开才进行下一步。 print(timeStampToTime(time.time())) except Exception as e: print("Except:", e) print("加载页面太慢,直接停止加载,继续下一步操作") print(timeStampToTime(time.time()), config_dict[item].get("URL")) #不需要做,timeout后自动停止加载了。 #下面对chrome都不起作用 #driver.execute_script('window.stop ? window.stop() : document.execCommand("Stop");') #driver.execute_script("window.stop()") # finally: # pass # driver.close() try: # 更好的方式 ele = driver.find_element_by_xpath( '//div[@class="dd"]/span[@class="p-price"]/span[contains(@class,"price")]' ) #print(ele) log.logInfo(driver.title + ": " + ele.text, log_file) if float(ele.text) < config_dict[item].get("ExpectedPrice"): #发送邮件提醒 print(driver.title) print(ele.text) sendmail.sendEmail( config_dict[item].get("Email", "*****@*****.**"), config_dict[item].get("URL") + " " + driver.title + ":" + ele.text) except Exception as e: print(e) log.logInfo("find_element_by_xpath error") time.sleep(30)
import requests import json from config import watchedCryptos, endpoint, mailConfig from sendmail import sendEmail for crypto in watchedCryptos: url = endpoint+crypto["pair"] r = requests.get(url) rates = json.loads(r.content) if float(rates["last"]) < crypto["min"] or float(rates["last"]) > crypto["max"]: print(f"Pair {crypto['pair']} reached value {rates['last']}") sendEmail(crypto["pair"], rates["last"], mailConfig)
(50, 50), 2, 0.8, (0, 0, 0), 1, cv2.LINE_AA) else: cv2.putText( img, str(time.strftime("%a %b %d,%Y %H:%M:%S", time.localtime())), (50, 50), 2, 0.8, (255, 255, 255), 1, cv2.LINE_AA) if num > 0 and t % 5 == 0 and flag: for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) roi_color = img[y:y + h, x:x + w] cv2.imwrite('faces_detected.jpg', img) cv2.imwrite('images/' + str(x) + str(y) + '_faces.jpg', roi_color) image_name.append('images/' + str(x) + str(y) + '_faces.jpg') print(len(image_name), image_name) prevnum = num sendmail.sendEmail(image_name, num, 'faces_detected.jpg') flag = False # time.sleep(1) if num != prevnum: # print(flag) image_name.clear() flag = True cv2.imshow('frame', img) if cv2.waitKey(1) == ord('q'): break cam.release() cv2.destroyAllWindows()
def new_https_main(): global china_cities with open(china_file, 'r') as f: text = f.read() china_cities = json.loads(text) #printPor() taiwan = { 'name': '台湾', 'level': 1, 'code': '', 'child': [{ 'name': '市辖区', 'level': 2, 'code': '', 'child': None }] } hongkong = { 'name': '香港', 'level': 1, 'code': '', 'child': [{ 'name': '市辖区', 'level': 2, 'code': '', 'child': None }] } macao = { 'name': '澳门', 'level': 1, 'code': '', 'child': [{ 'name': '市辖区', 'level': 2, 'code': '', 'child': None }] } china_cities.append(taiwan) china_cities.append(hongkong) china_cities.append(macao) #每个省份开一个线程。 threads = [] for i in range(len(china_cities)): t = threading.Thread(target=process_province_request, args=("Thread-" + str(i), i)) t.start() threads.append(t) for t in threads: t.join() print(statics_data) result = sorted(statics_data.items(), key=lambda x: x[1].get("num"), reverse=True) exportExcel(result) with open(data_name, "w+") as f: f.write( json.dumps(result, ensure_ascii=False, indent=4, separators=(',', ': '))) #email_package.sendmail.sendEmail(email_list,'海底捞门店','Fighting',[execel_name]) sendmail.sendEmail(email_list, '海底捞门店数据', 'Fighting', [execel_name])