def __init__(self, user_name: str, password: str, qq: str, other_config: dict): self.user_name = user_name self.password = password self.qq = qq self.WATCH_TIME_INTERVAL = other_config['interval'] self.TIME_DELTA = other_config['time_delta'] self.visited_items = self.get_read_items() self.data = self.get_items() self.email_sender = SendEmail("学习通消息通知")
def SendMail(self): self.getNow() with open(self.root + self.student.name + "本学期成绩" + ".txt", "r", encoding="utf-8") as f: data = f.readlines() SendEmail(''.join(data))
#!/usr/bin/python # -*- coding: utf-8 -*- # Filename: send_email.py import sys reload(sys) sys.setdefaultencoding('utf-8') from mail import SendEmail content = "这是一封来自DNS监控的测试邮件,请勿回复!" title = "这是一封来自DNS监控的测试邮件,请勿回复!" mailto_list = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ] mail = SendEmail('smtp.efly.cc', '*****@*****.**', 'eflydns123') mail.sendTxtMail(mailto_list, title, content)
ret = xh.getDict() #pprint(ret) string = ret['description'] string = string.split('\n') string = string[3] string = string[0:-8] string = string.split(', ') weather = string[0] tp = string[1] title = '肥猪心,早晨,今日圣安天气:' + str(weather) + ',当前体感温度:' + str(tp) + "℃,气温渐冷,注意保暖" content = "<h1>早晨啦,亲!</h1><br><h1>今天天气:" + str(weather) + ",当前体感温度:" + str(tp) + "℃</h1><br><h1>正式上课了!不要再赖床了!记得忙碌之余多活动活动,多喝水,别再熬夜了</h1><br><h1>注意身体,有空的话多留点时间跟我Facetime啦!</h1><br><h1>爱你!</h1>" mailto_list = ['*****@*****.**'] #mailto_list = ['*****@*****.**'] mail = SendEmail('smtp.163.com', '*****@*****.**', 'xinyi520') if mail.sendImageMail(mailto_list, title , content): print "发送成功" else: print "发送失败" backup_list = ['*****@*****.**'] mail = SendEmail('smtp.163.com', '*****@*****.**', 'xinyi520') if mail.sendImageMail(backup_list, title , content): print "发送成功" else: print "发送失败"
if 'message' in data: msg = data['message'] if ret == 0: if status[addr] == 'false': now = datetime.datetime.now() now = str(now) now = now[:19] sql = "update server_list set `status` = 'true',`updatetime` = '" + now + "' where `ip` = '" + addr + "'" content = "【EflyDNS监控提醒】:DNSMgr[" + addr + "]已重新恢复正常服务!" title = "【EflyDNS监控提醒】:DNSMgr[" + addr + "]已重新恢复正常服务!" #mailto_list = ['*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**'] mailto_list = ['*****@*****.**'] mail = SendEmail('smtp.efly.cc', '*****@*****.**', 'eflydns123') mail.sendTxtMail(mailto_list, title , content) cursor.execute(sql) else: if status[addr] == 'true': now = datetime.datetime.now() now = str(now) now = now[:19] sql = "update server_list set `status` = 'false',`updatetime` = '" + now + "' where `ip` = '" + addr + "'" title = "【EflyDNS监控提醒】:DNSMgr[" + addr + "]状态异常,请检查是否存在问题!" content = "【EflyDNS监控提醒】:DNSMgr[" + addr + "]状态异常,请检查是否存在问题!</br> 错误原因:" + str(msg) #mailto_list = ['*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**']
#pprint(ret) string = ret['description'] string = string.split('\n') string = string[3] string = string[0:-8] string = string.split(', ') weather = string[0] tp = string[1] title = '肥猪心,早晨,今日圣安天气:' + str(weather) + ',当前体感温度:' + str(tp) + "℃,气温渐冷,注意保暖" content = "<h1>早晨啦,亲!</h1><br><h1>今天天气:" + str(weather) + ",当前体感温度:" + str( tp ) + "℃</h1><br><h1>正式上课了!不要再赖床了!记得忙碌之余多活动活动,多喝水,别再熬夜了</h1><br><h1>注意身体,有空的话多留点时间跟我Facetime啦!</h1><br><h1>爱你!</h1>" mailto_list = ['*****@*****.**'] #mailto_list = ['*****@*****.**'] mail = SendEmail('smtp.163.com', '*****@*****.**', 'xinyi520') if mail.sendImageMail(mailto_list, title, content): print "发送成功" else: print "发送失败" backup_list = ['*****@*****.**'] mail = SendEmail('smtp.163.com', '*****@*****.**', 'xinyi520') if mail.sendImageMail(backup_list, title, content): print "发送成功" else: print "发送失败"
class XueXiTongMessageTrans(): READ_ITEMS_FILE = "read_msg.json" # 存放已阅览消息的 id def __init__(self, user_name: str, password: str, qq: str, other_config: dict): self.user_name = user_name self.password = password self.qq = qq self.WATCH_TIME_INTERVAL = other_config['interval'] self.TIME_DELTA = other_config['time_delta'] self.visited_items = self.get_read_items() self.data = self.get_items() self.email_sender = SendEmail("学习通消息通知") def get_crypt_user(self): password = str(base64.b64encode(self.password.encode('utf-8'))) return { 'uname': self.user_name, 'password': password[2:len(password) - 1] } def get_cookies(self): """ 需要的 Cookies 字段为 fid _d UID vc3 fid=xxx; _d=160303033xxxx; UID=103194xxx; vc3=xxxJBRbWTRtevhuICV9V0Yp8fr6zl%2FPi%2BDPdgafchZMf904ECvfqsryiX7O8M9%2BiEmGhf4mqqdT6%2FHzDuJNgXZXY07vvm096RrKWf88PaucZ1Kcmunbq0I1DCcD99EAHujAkVolTzjD%2FCC2OXcH6FeXn3R0AMR8y82eIeEitndU%3D3847ebbce53753ff6b3c482291b09xxx """ user = self.get_crypt_user() data = { **user, 'fid': -1, 'refer': 'http%3A%2F%2Fi.chaoxing.com', 't': 'true' } req = requests.post('https://passport2.chaoxing.com/fanyalogin', data=data) cookies_obj = req.cookies._cookies['.chaoxing.com']['/'] cookies = f"fid={cookies_obj['fid'].value}; _d={cookies_obj['_d'].value}; UID={cookies_obj['UID'].value}; vc3={cookies_obj['vc3'].value}" return cookies def get_items(self): # 获取学习通消息 params = { "type": 2, "notice_type": '', "lastValue": '', "folderUUID": '', "kw": '', "startTime": '', "endTime": '', "gKw": '', "gName": '' } headers = { "Accept": "application/json, text/javascript, */*; q=0.01", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Edg/85.0.564.70", "Cookie": self.get_cookies() } req = requests.post( 'http://notice.chaoxing.com/pc/notice/getNoticeList', data=params, headers=headers) return json.loads(req.content) def watch_items(self): def match_time(cur_time: datetime, pre_time: datetime): # 判断时间之差是否大于 TIME_DELTA,大于 TIME_DELTA 说明第一条消息已经是很早之前的消息, # 之后就没必要去判断其他消息 return (cur_time - pre_time).days <= self.TIME_DELTA def send_email(email_sender: SendEmail, content: str): qq_email = f"{self.qq}@qq.com" email_sender.send(content, '', [qq_email]) items = self.data["notices"]["list"] first_item_time = datetime.strptime(items[0]["completeTime"], "%Y-%m-%d %H:%M:%S") current_time = datetime.today() assert match_time(current_time, first_item_time), '\n\n无最新消息\n\n' for item in items: id = item["idCode"] item_time = datetime.strptime(item["completeTime"], "%Y-%m-%d %H:%M:%S") if match_time(current_time, item_time) and \ id not in self.visited_items: print("收到新消息!") content = item["content"] send_email(self.email_sender, content) self.visited_items.append(id) else: break self.set_read_items() print("\n\n消息扫描完毕, 扫描完成时间 {}\n\n".format(datetime.today())) self.email_sender.quit() def get_read_items(self): try: with open(self.READ_ITEMS_FILE, 'r') as file_obj: data = json.load(file_obj) except Exception: with open(self.READ_ITEMS_FILE, 'a'): pass return [] return data def set_read_items(self): with open(self.READ_ITEMS_FILE, 'w') as file_obj: json.dump(self.visited_items, file_obj)
def send_email(email_sender: SendEmail, content: str): qq_email = f"{self.qq}@qq.com" email_sender.send(content, '', [qq_email])
from pic import PictureMaker from deleter import TrashCan app = Flask(__name__) # set it to a random string app.secret_key = 'any random string that are long enough' # set this to path/to/your/database/backend/program database_exec_path = './train_modified' rand_exec_path = './gen_rand' graph_exec_path = './static/' app.pipe = PipeLine(database_exec_path) app.rand = PipeLine(rand_exec_path) app.email = SendEmail() app.pic_make = PictureMaker(graph_exec_path) app.trash_can = TrashCan() # add_train 1 C1001(长春-延吉西) C 4 2 硬卧 软卧 # 长春 xx:xx 05:47 xx:xx ¥0.0 ¥0.0 # 吉林 06:27 06:29 00:02 ¥478.97 ¥980.89 # 敦化 07:23 07:25 00:02 ¥911.62 ¥2748.9 # 延吉西 08:04 08:04 xx:xx ¥1454.54 ¥2489.5 class StationInfo(object): def __init__(self, seat_num): self.name = None self.arrive = None self.leave = None