Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add+Update] 新增基于HTML发邮件提醒+修改Application 放一些定时任务 ,可能会导致阻塞, 放到了crontab…
…_app
- Loading branch information
杨红飞
committed
Mar 21, 2019
1 parent
f625cc4
commit fbe26f5
Showing
16 changed files
with
489 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/3/21 19:52 | ||
# @Author : Fred Yangxiaofei | ||
# @File : crontab_app.py | ||
# @Role : Application 放一些定时任务 ,可能会导致阻塞 | ||
|
||
|
||
import tornado | ||
from websdk.application import Application as myApplication | ||
from biz.tail_data import tail_data | ||
|
||
|
||
class Application(myApplication): | ||
def __init__(self, **settings): | ||
urls = [] | ||
tailed_callback = tornado.ioloop.PeriodicCallback(tail_data, 21600000) # 6小时执行一次 | ||
tailed_callback.start() | ||
super(Application, self).__init__(urls, **settings) | ||
|
||
|
||
if __name__ == '__main__': | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/3/21 15:10 | ||
# @Author : Fred Yangxiaofei | ||
# @File : get_userinfo.py | ||
# @Role : 获取CODO平台用户详细信息 | ||
|
||
|
||
from libs.redis_connect import redis_conn | ||
from websdk.consts import const | ||
|
||
|
||
def get_user_info(): | ||
""" | ||
从现有redis里面获取用户信息,如:Email,SMS等 | ||
:return: | ||
""" | ||
# 集合 | ||
data_set = redis_conn.smembers(const.USERS_INFO) | ||
# 集合转list | ||
userdata = list(data_set) | ||
# PS:这里codo后端会把数据主动写redis里面,假数据类型:user_data:['{"nickname:杨红飞", "email": "test@domain.cn", "tel": "10000000001"}','{"nickname:杨红飞02", "email": "test02@domain.cn", "tel": "10000000002"}'] | ||
return userdata | ||
|
||
|
||
if __name__ == '__main__': | ||
get_user_info() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/3/21 11:13 | ||
# @Author : Fred Yangxiaofei | ||
# @File : paid_mg_handler.py | ||
# @Role : 付费管理路由 | ||
|
||
|
||
import tornado.web | ||
import json | ||
from libs.database import model_to_dict | ||
from models.paid_mg import PaidMG | ||
from websdk.db_context import DBContext | ||
from websdk.utils import SendSms, SendMail | ||
from websdk.consts import const | ||
from websdk.tools import convert | ||
from websdk.configs import configs | ||
|
||
|
||
class PaidMGHandler(tornado.web.RequestHandler): | ||
def get(self, *args, **kwargs): | ||
key = self.get_argument('key', default=None, strip=True) | ||
value = self.get_argument('value', default=None, strip=True) | ||
paid_list = [] | ||
with DBContext('w') as session: | ||
if key and value: | ||
paid_data = session.query(PaidMG).filter_by(**{key: value}).all() | ||
else: | ||
paid_data = session.query(PaidMG).all() | ||
|
||
for data in paid_data: | ||
data_dict = model_to_dict(data) | ||
data_dict['paid_start_time'] = str(data_dict['paid_start_time']) | ||
data_dict['paid_end_time'] = str(data_dict['paid_end_time']) | ||
data_dict['create_at'] = str(data_dict['create_at']) | ||
data_dict['update_at'] = str(data_dict['update_at']) | ||
paid_list.append(data_dict) | ||
return self.write(dict(code=0, msg='获取成功', data=paid_list)) | ||
|
||
def post(self, *args, **kwargs): | ||
data = json.loads(self.request.body.decode("utf-8")) | ||
paid_name = data.get('paid_name', None) | ||
paid_start_time = data.get('paid_start_time', None) | ||
paid_end_time = data.get('paid_end_time', None) | ||
reminder_day = data.get('reminder_day', None) | ||
nicknames = data.get('nicknames', None) | ||
|
||
if not paid_name or not paid_start_time or not paid_end_time or not reminder_day or not nicknames: | ||
return self.write(dict(code=-2, msg='关键参数不能为空')) | ||
|
||
with DBContext('w', None, True) as session: | ||
session.add( | ||
PaidMG(paid_name=paid_name, paid_start_time=paid_start_time, paid_end_time=paid_end_time, | ||
reminder_day=reminder_day, nicknames=nicknames)) | ||
|
||
self.write(dict(code=0, msg='添加成功')) | ||
|
||
def delete(self, *args, **kwargs): | ||
data = json.loads(self.request.body.decode("utf-8")) | ||
paid_id = data.get('id') | ||
if not paid_id: | ||
return self.write(dict(code=-2, msg='关键参数不能为空')) | ||
|
||
with DBContext('w', None, True) as session: | ||
session.query(PaidMG).filter(PaidMG.id == paid_id).delete(synchronize_session=False) | ||
|
||
self.write(dict(code=0, msg='删除成功')) | ||
|
||
def patch(self, *args, **kwargs): | ||
data = json.loads(self.request.body.decode("utf-8")) | ||
paid_id = data.get('id') | ||
paid_name = data.get('paid_name', None) | ||
paid_start_time = data.get('paid_start_time', None) | ||
paid_end_time = data.get('paid_end_time', None) | ||
reminder_day = data.get('reminder_day', None) | ||
nicknames = data.get('nicknames', None) | ||
|
||
update_info = { | ||
"paid_name": paid_name, | ||
"paid_start_time": paid_start_time, | ||
"paid_end_time": paid_end_time, | ||
"reminder_day": reminder_day, | ||
"nicknames": nicknames | ||
} | ||
with DBContext('w', None, True) as session: | ||
session.query(PaidMG).filter(PaidMG.id == paid_id).update(update_info) | ||
|
||
self.write(dict(code=0, msg='更新成功')) | ||
|
||
|
||
paid_urls = [ | ||
(r"/v1/tools/paid/", PaidMGHandler) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.