def send_email(): response = Response() response.headers['Content-Type'] = 'application/json' response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Headers'] = '*' if request.method == 'OPTIONS': return response elif request.method == 'POST': message = json.loads(request.get_data(as_text = True)) name = message.get('name') token = message.get('token', '') if name is None: return response_json(code=1, message='Name is required') result = confirm_token(token) if result is False: return response_json(code=2, message='Token is not available, plz check your latest email') email = result['email'] if is_token_unused(token): # 先确定下是不是志愿者列表中的token 并且是否注册过 没问题的话开始做图片 update_status(email, 2) update_name(email,name) try: wc.write_to_pic(name,email,token) return_json = {'code': 0, 'message': 'You have submitted your information successful, the certificate is sent to you, please check your email', 'data': None} response.data = return_msg(return_json) return response except Exception as e: # 发送邮件或者创建图片错误 可能是邮件有问题 logger.error(e) return response_json(4, str(e)) else: return response_json(3, 'You have submitted your information successful, please check your email')
def send_email(): if request.method == 'POST': message = json.loads(request.get_data(as_text = True)) name = message['name'] token = message['token'] result = confirm_token(token) # 没有每个人唯一的Key response = Response() response.headers['Content-Type'] = 'application/json' response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Headers'] = '*' if request.method == 'OPTIONS': return response return_json = {'code': 1, 'message': '网络异常', 'data': None} response.data = return_msg(return_json) if result == False: return response email = result['email'] if is_token_unused(token): # 先确定下是不是志愿者列表中的token 并且是否注册过 没问题的话开始做图片 update_status(email, 2) try: wc.write_to_pic(name,email) return_json = {'code': 0, 'message': 'You have submitted your information successful, the certificate is sent to you, please check your email', 'data': None} response.data = return_msg(return_json) return response except : #发送邮件或者创建图片错误 可能是邮件有问题 return return_msg("5") else: response.data = return_msg(return_json) return response # Key被用过了
def button(bot, update): query = update.callback_query chat_id = query.message.chat_id if query.data == "1": model.update_status(chat_id, "add") bot.send_message(chat_id=chat_id, text="Ok, Enter a movie name.") elif query.data == "2": model.update_status(chat_id, "get_movies") bot.send_message(chat_id=chat_id, text="Share your location with us.") elif query.data == "3": m = db_management.DBManagementHelper().get_movies_list(chat_id) if db_management.DBManagementHelper().get_index(chat_id) < 3: publish_result(m, bot, chat_id) else: bot.send_message(chat_id=chat_id, text="Sorry, no more recommended movies :(") elif query.data == "100": model.choose_movie(chat_id, db_management.DBManagementHelper().get_movies_list(chat_id)[0]) bot.send_message(chat_id=chat_id, text="Great choice!\nYou will be notified 1 hour before.") jobs.run_once(notify, 5, context=chat_id) elif query.data == "101": model.choose_movie(chat_id, db_management.DBManagementHelper().get_movies_list(chat_id)[1]) bot.send_message(chat_id=chat_id, text="Great choice!\nYou will be notified 1 hour before.") jobs.run_once(notify, 5, context=chat_id) elif query.data == "102": model.choose_movie(chat_id, db_management.DBManagementHelper().get_movies_list(chat_id)[2]) bot.send_message(chat_id=chat_id, text="Great choice!\nYou will be notified 1 hour before.") jobs.run_once(notify, 5, context=chat_id)
def change_status_to_0(): db = TinyDB("data.json") People = Query() target_users = db.search(People.status.one_of([2, 3])) for user in target_users: update_status(user['email'], 0) db.close()
def send_email_to_status_0(): db = TinyDB("data.json") People = Query() target_users = db.search(People.status == 1) print('there are %s target_users' % len(target_users)) for user in target_users: update_status(user['email'], 0) print('all done') db.close()
def send_notice_email(): """ 为当前邮箱状态为0的用户发送提醒邮件 :return: """ db = TinyDB("data.json") People = Query() target_users = db.search(People.status == 0) for user in target_users: send_email( to_email=user.email, subject='快来领取您的wuhan2020证书', content='感谢您的辛苦付出,请点击链接领取您的志愿证书\n', ) update_status(email=user.email, status=1) time.sleep(random.random() * 10)
def write_to_pic(name, email): # 执行完这个方法后生成一个 result.png 图片 可加入email参数 number = get_number(email) # 用这个方法获取到编号 update_status(email) # use 参数 变为1 生成了证书 im = Image.open("pic.jpg") draw = ImageDraw.Draw(im) font_name = ImageFont.truetype('font/1.ttf', 55) # 名字的字体和字号 font_number = ImageFont.truetype('font/1.ttf', size=35) # 编号的字体和字号 imwidth, imheight = im.size font_width, font_height = draw.textsize(name, font_name) # 获取名字的大小 draw.text(((imwidth - font_width - font_name.getoffset(name)[0]) / 2, 470), text=name, font=font_name, fill=(0, 0, 0)) # 写上名字 x使用了居中 draw.text(xy=(310, 285), text=number, font=font_number) # 写上编号 im.save("result.png") send_email(email) # 可直接发送到邮箱
def start(bot, update): chat_id = update.message.chat_id db_management.DBManagementHelper().update_index(chat_id, 0) db_management.DBManagement().update_movie(chat_id) exist_user = "" if not model.add_user(chat_id): model.update_status(chat_id, 'start') exist_user = "******" message = f"Welcome {exist_user} to Go2Movie bot!\n" \ "Give me an example of a movie you like and I'll find you a movie you'll like." logger.info(f"> Start chat #{chat_id}") keyboard = [[InlineKeyboardButton("Add movie", callback_data='1')]] if not exist_user else \ [[InlineKeyboardButton("Add movie", callback_data='1'), InlineKeyboardButton("Get recommendations", callback_data='2')]] reply_markup = InlineKeyboardMarkup(keyboard) bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup)
def write_to_pic(name, email): # 执行完这个方法后生成一个 result.png 图片 可加入email参数 number = get_number(email) # 用这个方法获取到编号 date_str = datetime.datetime.strftime(datetime.datetime.now(), '%Y年%m月%d日') #获取日期 update_status(email) # use 参数 变为1 生成了证书 im = Image.open("pic.jpg") draw = ImageDraw.Draw(im) font_name = ImageFont.truetype('font/1.ttf', size=55) # 名字的字体和字号 font_number = ImageFont.truetype('font/2.ttf', size=35) # 编号的字体和字号 setFontdate = ImageFont.truetype('font/DENG.TTF', size=28) # date字体路径 imwidth, imheight = im.size font_width, font_height = draw.textsize(name, font_name) # 获取名字的大小 draw.text(((imwidth - font_width - font_name.getoffset(name)[0]) / 2, 470), text=name, font=font_name, fill=(0, 0, 0)) # 写上名字 x使用了居中 draw.text(xy=(310, 285), text=number, font=font_number) # 写上编号 draw.text((434, 900), date_str, font=setFontdate, fill=(0, 0, 0)) # 写上日期 image_file = 'result.png' im.save(image_file) update_status(email, 3) send_email( to_email=email, subject='请领取您的志愿者证书', content= '您好,附件中有您的证书\n\n\nwuhan2020 开源社区\n\n\n社区网址:<a href="https://community.wuhan2020.org.cn/">https://community.wuhan2020.org.cn/</a>', attachment=[image_file]) update_status(email, 4)
def write_to_pic(name, email, token): # 执行完这个方法后生成一个 result.png 图片 可加入email参数 number = get_number(email) # 用这个方法获取到编号 date_str = datetime.datetime.strftime(datetime.datetime.now(), '%Y年%m月%d日') #获取日期 update_status(email) # use 参数 变为1 生成了证书 org_config = get_org_config() im = Image.open("pic.jpg") draw = ImageDraw.Draw(im) font_name = ImageFont.truetype('font/1.ttf', size=55) # 名字的字体和字号 font_number = ImageFont.truetype('font/2.ttf', size=35) # 编号的字体和字号 setFontdate = ImageFont.truetype('font/DENG.TTF', size=28) # date字体路径 imwidth, imheight = im.size font_width, font_height = draw.textsize(name, font_name) # 获取名字的大小 horizontal_offset = (font_width - font_name.getoffset(name)[0]) / 2 draw.text((org_config["name_horizontal_pos"] - horizontal_offset, org_config['name_vertical_pos']), text=name, font=font_name, fill=(0, 0, 0)) # 写上名字 x使用了居中 if org_config["serial_number_horizontal_pos"] > 0: draw.text(xy=(org_config["serial_number_horizontal_pos"], org_config["serial_number_vertical_pos"]), text=number, font=font_number) # 写上编号 if org_config["date_horizontal_pos"] > 0: draw.text((org_config["date_horizontal_pos"], org_config["date_vertical_pos"]), date_str, font=setFontdate, fill=(0, 0, 0)) # 写上日期 image_file = 'images/%s.png' % token im.save(image_file) update_status(email, 3) content = '您好,附件中有您的证书\n\n\n' content += org_config["name"] content += '\n\n\n网址:<a href="{0}">{0}</a>'.format(org_config["website"]) send_email(to_email=email, subject='请领取您的志愿者证书', content=content, attachment=[image_file]) update_status(email, 4)
def update(id): if request.method == 'POST': status = request.form['status'] model.update_status(status, id) todos = model.get_all_todos() return render_template('index.html', todos=todos)
def search_by_email(email): db = TinyDB("data.json") People = Query() target_user = db.search(People.email.matches('.*%s.*' % email)) for user in target_user: print(user) db.close() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--action', default='search_by_email', choices=['search_by_email', 'reset_status']) parser.add_argument('email') args = parser.parse_args() if args.action == 'search_by_email': search_by_email(args.email) elif args.action == 'reset_status': update_status(args.email, status=0) else: # change_status_to_0() # search_by_email('') # search_by_email('') # emails = ('*****@*****.**', ) # for i in emails: # update_status(i, 0) count_status()