def cycle(): mylist = get_hitsz() post_list = [] maxid = get_maxid() tmax = maxid for item in mylist: item_id = get_strid(item["href"]) if(item_id > maxid): post_list.append(item) if(item_id > tmax): tmax = item_id ylib.log_pf("new news list length : " + str(len(post_list)) ); if len(post_list) > 0: ylib.log_pf("新增加新闻") for item in post_list: ylib.log_pf(item["text"].replace(".","") + " " + item["href"]) mystr = "<h3> ^V^ </h3>" for item in post_list: mystr += "<a href ='" + item["href"] + "'>"+ "<p>" + item["text"] + "</p>" + "</a>" if tmax != maxid: write_maxid(tmax) import my_email as me import user subject = "Fresh news in : " + str(ylib.get_now_time()) for item in user.users: import time time.sleep(5) if me.send_mail(item.email,subject,mystr) == 1: ylib.log_pf(item.name + " 发送成功") else: ylib.log_pf(item.name + " 发送不成功")
try: driver.get('https://naver.com') keyword = input('검색어를 입력하세요:' ) elem = driver.find_element_by_id('query') elem.send_keys(keyword) elem.send_keys(Keys.RETURN) div = driver.find_element_by_class_name('_blogBase') #elem = div.find_element_by_tag_name('ul') blogs = div.find_elements_by_xpath('./ul/li') for blog in blogs: title_tag = blog.find_element_by_class_name('sh_blog_title') link = title_tag.get_attribute('href') pub_date_tag = blog.find_element_by_class_name('txt_inline') sheet.append([title_tag.text, link, pub_date_tag.text]) except Exception as e: print(e) finally: driver.quit() file_name = 'result.xlsx' xlsx.save(file_name) from my_email import send_mail send_mail('ismartkorea', '*****@*****.**', '네이버 검색 결과입니다.', file_name)
from openpyxl import Workbook import ssl base_rss_url = 'https://news.google.com/news/rss/headlines/section/topic' business_rss = base_rss_url + quote('/BUSINESS.ko_kr/경제?ned=kr&hl=ko') tech_rss = base_rss_url + quote('/SCITECH.ko_kr/과학기술?ned=kr&hl=ko') health_rss = base_rss_url + quote('/HEALTH.ko_kr/건강?ned=kr&hl=ko') xlsx = Workbook() business_sheet = xlsx.create_sheet('경제') business_sheet.append(['기사 제목', '링크', '날짜']) ssl._create_default_https_context = ssl._create_unverified_context news_list = feedparser.parse(business_rss) for news in news_list['items']: business_sheet.append([news['title'], news['link'], news['published']]) tech_sheet = xlsx.create_sheet('과학기술') tech_sheet.append(['기사 제목', '링크', '날짜']) news_list = feedparser.parse(tech_rss) for news in news_list['items']: tech_sheet.append([news['title'], news['link'], news['published']]) health_sheet = xlsx.create_sheet('건강') health_sheet.append(['기사 제목', '링크', '날짜']) news_list = feedparser.parse(health_rss) for news in news_list['items']: health_sheet.append([news['title'], news['link'], news['published']]) file_name = 'news_list.xlsx' xlsx.save(file_name) send_mail('이태화', '*****@*****.**', '뉴스 수집 결과입니다.', file_name)
title_tag = driver.find_element_by_xpath( "//div[contains(@class,'heading')]/h2") column = string.ascii_uppercase[column_idx] worksheet[column + '1'] = title_tag.text prev_price = worksheet[column + '2'].value curr_price = price_tag.text if prev_price and prev_price != curr_price: changes.append((title_tag.text, prev_price, curr_price)) worksheet[column + '2'] = price_tag.text column_idx += 1 worksheet.append(row) result_xlsx.save(file_path) if changes: from my_email import send_mail contents = str(today)[:-7] + ': 가격이 변동된 상품이 있습니다.\n\n' for c in changes: contents += '(%s) %s => %s\n' % (c[0], c[1], c[2]) send_mail('이태화', '*****@*****.**', contents) except Exception as e: print(e) finally: driver.quit()
encoders.encode_base64(file_data) from os.path import basename filename = basename(attachment) file_data.add_header('Content-Disposition', 'attachment', filename=filename) msg.attach(file_data) smtp = SMTP_SSL(SMTP_SERVER, SMTP_PORT) smtp.login(SMTP_USER, SMTP_PASSWORD) smtp.sendmail(SMTP_USER, addr, msg.as_string()) smtp.close() #엑셀로부터 데이터 읽어오기 from my_email import send_mail from openpyxl import load_workbook xlsx = load_workbook('수강생_결제정보.xlsx', read_only=True) sheet = xlsx.active for row in sheet.iter_rows(): name = row[0].value mail = row[1].value status = row[3].value if status == '결제완료': contents = '결제완료가 확인되어 커리큘럼을 안내해드립니다.' send_mail(name, mail, contents, '커리큘럼.xlsx')
try: driver.get('http://11st.co.kr') elem = driver.find_element_by_id('AKCKwd') elem.send_keys('자전거') elem.send_keys(Keys.RETURN) from openpyxl import Workbook result_xlsx = Workbook() worksheet = result_xlsx.active worksheet.append(['판매자 이름', '상품명', '가격']) elems = driver.find_elements_by_xpath("//li[contains(@id, 'thisClick_')]") for elem in elems: title_tag = elem.find_element_by_class_name('info_tit') # print(title_tag.text) mall_tag = elem.find_element_by_class_name('benefit_tit') price_tag = elem.find_element_by_class_name('sale_price') print(mall_tag.text, title_tag.text, price_tag.text) worksheet.append([mall_tag.text, title_tag.text, price_tag.text]) file_name = 'C:\\python\\examples\\2.6\\11st_result.xlsx' result_xlsx.save(file_name) from my_email import send_mail send_mail('이태화', '*****@*****.**', '테스트', file_name) except Exception as e: print(e) finally: driver.quit()
driver.get('https://www.naver.com/') elem = driver.find_element_by_id('query') elem.send_keys("파이썬") elem.send_keys(Keys.RETURN) div = driver.find_element_by_class_name('_blogBase') blogs = div.find_elements_by_xpath('./ul/li') # print(blogs[0].text) for blog in blogs: title_tag = blog.find_element_by_class_name('sh_blog_title') # print(title_tag.text) link = title_tag.get_attribute('href') # print(link) pub_data_tag = blog.find_element_by_class_name('txt_inline') # print(pub_data_tag.text) sheet.append([title_tag.text, link, pub_data_tag.text]) except Exception as e: print(e) finally: time.sleep(1) driver.quit() file_name = 'd:/result.xlsx' xlsx.save(file_name) from my_email import send_mail # send_mail('haejungkim', '*****@*****.**', '네이버 검색 결과입니다') send_mail('haejungkim', '*****@*****.**', '네이버 검색 결과입니다', file_name)
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 07:24:46 2020 @author: USER """ from datetime import datetime from my_email import send_mail today = datetime.now() todate = today.strftime("%b_%d_%Y") fname = 'joony_quiz_' + today.strftime("%b_%d_%Y") + '.txt' fpath = 'D://Coding//' attachment = fpath + fname contents = todate + '의 퀴즈 - 10까지 덧셈' send_mail('Taejun', '*****@*****.**', contents) #, attachment)
from my_email import send_mail send_mail('이태화', '*****@*****.**', '테스트내용')
with open(os.path.join(os.getcwd(), file_), 'w', newline='', encoding="utf-8") as csvfile: writer = csv.writer(csvfile) writer.writerows(tabla) directory = os.path.join(os.getcwd(), "output") if not os.path.exists(directory): os.makedirs(directory) d = open_browser() ctas = getdias(d) get_nfl(d, ctas) d.close() with zipfile.ZipFile(os.path.join(os.getcwd(), "output/pronosports.zip"), 'w') as myzip: for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(".csv"): myzip.write(os.path.join(directory, filename), filename) for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(".csv"): os.remove(os.path.join(directory, filename)) send_mail(os.path.join(os.getcwd(), "output/pronosports.zip"), 'pronosports.zip') os.remove(os.path.join(os.getcwd(), "output/pronosports.zip"))