def compare_send_email(self, item_id, item_price_inner, item_name_inner): cursor = conn.cursor() sql = 'select user_price from monitor where item_id = %s' % item_id print '查询语句为:', sql cursor.execute(sql) user_price = cursor.fetchone( ) # user_price: tuple user_price[0]: decimal item_price: unicode if float( user_price[0]) >= float(item_price_inner): # 转为float才可以对比,可以改进 sql = 'update monitor set status = 0 where item_id = %s' % item_id cursor.execute(sql) conn.commit() sql = 'select user_email from user where user_id = ( select user_id from monitor where item_id = %s )' % item_id cursor.execute(sql) user_email = cursor.fetchone() user_email = str(user_email[0]) # 改进 email_text = '您监控的商品:' + str(item_name_inner) + ',现在价格为:' + str( item_price_inner) + ',您设定的价格为:' + str( user_price[0]) + ' 赶紧抢购吧!' email_zhuti = '您监控的商品降价了!' sendemail = SendEmail(email_text, 'admin', 'user', email_zhuti, user_email) sendemail.send() print '该商品降价,已发送邮件提醒用户' cursor.close()
def send_invitations(self): """ Assigns secret santa to every participant and sends an email invite to respective members informing the same. """ event_date_str = self.txt_date.get() if event_date_str: try: event_date = datetime.strptime(event_date_str, '%m/%d/%Y') except ValueError: messagebox.showerror("Error", "Invalid date format.") return event_date_str = datetime.strftime(event_date, "%A - %d %b, %Y") else: event_date_str = '-' budget = self.txt_budget.get() try: budget = int(budget) except ValueError: messagebox.showerror("Error", "Invalid budget value.") return email_dict = {} participants = [] for i in range(NO_OF_ENTITIES): email = self.txt_email[i].get() name = self.txt_name[i].get() if name and email: email_dict[email] = name participants.append(email) else: if email and not name: messagebox.showerror("Error", f"Name not found for entity no. {i+1}.") return if name and not email: messagebox.showerror("Error", f"Email mandatory for entity no. {i+1}.") return if (len(participants)) < 2: messagebox.showerror("Error", "Insufficient participants.") return random.shuffle(participants) email_formatter = EmailFormatter(event_date_str, budget) for i, _ in enumerate(participants): giver = participants[i] receiver = participants[(i + 1) % (len(participants))] send_email = SendEmail(['smtp.gmail.com', 587, \ '*****@*****.**', 'xxxxxxxxx'], True) send_email.send(from_name="Secret Santa Generator", to_address=[giver], \ subject=email_formatter.subject(email_dict[giver]), \ body=email_formatter.body(email_dict[giver], \ email_dict[receiver])) messagebox.showinfo("Success", "Invitations sent.")
def notify(self, subject, body, email_to): # initialize send mail class send_email = SendEmail() # print(body) send mail to active users send_email.send(email_to, subject, body) send_email.quit()
def compare_send_email(self, user_id_inner, item_id_inner, item_price_inner, item_name_inner): cursor = self.conn.cursor() try: sql = 'select user_price from monitor where item_id = %s and user_id = %s' % (item_id_inner, user_id_inner) # print 'SQL query: ', sql cursor.execute(sql) user_price = cursor.fetchone() # user_price: tuple, user_price[0]: decimal, item_price: unicode except mysql.connector.errors.InternalError: note = '拥有重复商品,每个商品只能有一个监控,否则会导致监控失败。' sql = 'update monitor set note = \'%s\' where item_id = %s and user_id = %s' % (note, item_id_inner, user_id_inner) print 'Have same item id in one user, skip this round.' cursor.execute(sql) self.conn.commit() cursor.close() return if float(item_price_inner) == -1.00: # 抓取到-1不发邮件,状态依然为1 note = '商品已经下架或者ID不正确。' sql = 'update monitor set note = \'%s\' where item_id = %s and user_id = %s' % (note, item_id_inner, user_id_inner) print 'Wrong item price: -1, skip this round.' cursor.execute(sql) self.conn.commit() cursor.close() return if float(user_price[0]) >= float(item_price_inner): # 转为float才可以对比,可以改进 # try: sql = 'update monitor set status = 0 where item_id = %s and user_id = %s' % (item_id_inner, user_id_inner) cursor.execute(sql) self.conn.commit() sql = 'select user_email from user where user_id = %s' % user_id_inner cursor.execute(sql) user_email = cursor.fetchone() user_email = str(user_email[0]) # linux可用,win会报下面的错误 # item_url = 'https://item.jd.com/' + item_id_inner + '.html' # 邮件网址,怀疑是垃圾邮件原因 email_text = '您监控的商品:' + item_name_inner + ',' + ',现在价格为:' + item_price_inner + ',您设定的价格为:' + str(user_price[0]) + ' 赶紧抢购吧!'.encode('utf-8') email_text = email_text email_zhuti = '您监控的商品降价了!' sendemail = SendEmail(email_text, 'admin', 'user', email_zhuti, user_email) sendemail.send() print '该商品降价,已发送邮件提醒用户' ''' except UnicodeEncodeError as e: sql = 'update monitor set status = 1 where item_id = %s and user_id = %s' % (item_id_inner, user_id_inner) cursor.execute(sql) self.conn.commit() print '发送邮件过程中发生错误,等待下轮重试,正在监控状态继续', e except UnicodeDecodeError as e: sql = 'update monitor set status = 1 where item_id = %s and user_id = %s' % (item_id_inner, user_id_inner) cursor.execute(sql) self.conn.commit() print '发送邮件过程中发生错误,等待下轮重试,正在监控状态继续', e ''' cursor.close()
def notif(self, notificon): global _notification_header global _notification_description # Get notification data from HTTP header try: new_notification_header = base64.urlsafe_b64decode(cherrypy.request.headers['NOTIFHEADER']) new_notification_description = base64.urlsafe_b64decode(cherrypy.request.headers['NOTIFDESCRIPTION']) except: # Maintain compatibility with old application new_notification_header = cherrypy.request.headers['NOTIFHEADER'].replace('\x00', '').decode('iso-8859-1', 'replace').encode('utf-8') new_notification_description = cherrypy.request.headers['NOTIFDESCRIPTION'].replace('\x00', '').decode('iso-8859-1', 'replace').encode('utf-8') # Ensure the notification is not a duplicate if (_notification_header != new_notification_header) \ or (_notification_description != new_notification_description): _notification_header = new_notification_header _notification_description = new_notification_description new_notification_description = new_notification_description[:-14] #remove (via twitter) ts = "https://twitter.com/search?q=" tweet = self.clean_tweet(new_notification_description) twitterSearch = ts + urllib.quote(tweet) sixWords = self.get_first_n_words(7,tweet) twitterSearchTwo = ts + urllib.quote(sixWords) bonus = self.add_description(new_notification_header, new_notification_description) now = datetime.datetime.now() if (not self.filter_tweet(tweet)): SendEmail.send(new_notification_header + " - " + new_notification_description, new_notification_description + "\n\n" + twitterSearch + "\n\n" + twitterSearchTwo + "\n\n" + bonus) logmessage = (now.strftime("%Y-%m-%d %H:%M") + " " + new_notification_header + " - " + new_notification_description) print (logmessage[:98].replace('\n', ' ')) return "true"
from get_message import GetMessage from send_email import SendEmail from database import Database if __name__ == '__main__': # Define variables to connect to MySQL database user = '******' # Set username of MySQL server password = '' # Set password of MySQL server d = Database(user, password) n = int(input("Number of queries")) for query in range(n): email=input("Email address") series = input("TV Series").split(',') message = "\n" #Create an object for Database class #Connect to database and insert the data in the table. d.write(email,series) for i in series: #Create an object for GetMessage class which can determine the next episode date of the TV Series. m = GetMessage(i) #print(a.get_imdb_url()) message+="Tv series name: "+i+"\n" message+="Status: "+m.get_episode_date()+"\n" #print(message) message+="\n" #Send the result to user's email e = SendEmail(email,message) e.send()
txtEmail += Html.br() + Html.hr() except Exception as e: txtEmail += Html.tag('p', 'FALHA AO RECUPERAR A TABELA DE RODIZIOS') print(e) try: saneparNivel = SaneparNivelReservatorioCrawler() niveis = saneparNivel.crawl(True) txtEmail += Html.tag('h2', 'NÍVEL DOS RESERVATÓRIOS') txtEmail += Html.tag('p', saneparNivel.data_atualizacao) txtEmail += Html.table(niveis, { 'border': 1, 'cellpadding': 5, 'cellspacing': 0, }) txtEmail += Html.tag( 'p', '*Sistema de Abastecimento de Água Integrado de Curitiba') except Exception as e: txtEmail += Html.tag( 'p', 'FALHA AO RECUPERAR DADOS DE NIVEIS DOS RESERVATÓRIOS') print(e) dt = datetime.datetime.now().astimezone( timezone('America/Sao_Paulo')).strftime("%d/%m/%Y %H:%M:%S") email = SendEmail() email.send('Rodízio Sanepar ' + dt, txtEmail)
from FlexCambio import FlexCambioCrawler from send_email import SendEmail import datetime from pytz import timezone from helpers.Html import Html txtEmail = Html.tag('h2', 'COTAÇÕES DO EURO') try: flexCrawler = FlexCambioCrawler() txtEmail += Html.table(flexCrawler.crawl(True), { 'border': 1, 'cellpadding': 5, 'cellspacing': 0, }) except Exception as e: txtEmail += Html.tag('p', 'FALHA AO RECUPERAR A TABELA DE COTAÇÕES') print(e) dt = datetime.datetime.now().astimezone(timezone('America/Sao_Paulo')).strftime("%d/%m/%Y %H:%M:%S") email = SendEmail() email.send('Cotação Euro '+dt, txtEmail)