Forráskód Böngészése

添加报警装饰器

ck 4 éve
szülő
commit
70d911ef00
4 módosított fájl, 89 hozzáadás és 23 törlés
  1. 13 3
      app/api_data/get_order.py
  2. 18 12
      app/api_data/order_util.py
  3. 41 7
      app/api_data/tg.py
  4. 17 1
      model/DingTalkUtils.py

+ 13 - 3
app/api_data/get_order.py

@@ -1,7 +1,7 @@
 from app.api_data.order_util import *
 from model.DataBaseUtils import MysqlUtils
 from concurrent.futures import ThreadPoolExecutor
-from model.DingTalkUtils import DingTalkUtils
+from model.DingTalkUtils import DingTalkUtils,DingTalkDecorators
 from app.api_data.platform_order.audio_qiyue import AudioQiyue
 from app.api_data.platform_order.youshuge import get_youshuge_order_task
 from app.api_data.platform_order.yuewen import get_yuewen_order_task
@@ -27,6 +27,7 @@ def get_new_account(plactform):
     return new_data
 
 
+@DingTalkDecorators("阳光")
 def yangguang(start=None, end=None, new=None):
     if start:
         start = start + ' 00:00:00'
@@ -67,6 +68,7 @@ def yangguang(start=None, end=None, new=None):
         parse_yg_data(vip_id, stage)
 
 
+@DingTalkDecorators("花生")
 def huasheng(start=None, end=None):
     if start is None:
         start = end = du.getNow()
@@ -83,6 +85,7 @@ def huasheng(start=None, end=None):
     executor.shutdown()
 
 
+@DingTalkDecorators("七悦")
 def qiyue(start=None, end=None, new=None):
     if start is None:
         start = end = du.getNow()
@@ -95,6 +98,7 @@ def qiyue(start=None, end=None, new=None):
         get_qiyue_order_task(start, end, account)
 
 
+@DingTalkDecorators("文鼎")
 def wending(start=None, end=None, new=None):
     if start is None:
         start = end = du.getNow()
@@ -108,6 +112,7 @@ def wending(start=None, end=None, new=None):
         get_wd_order_task(start, end, account)
 
 
+@DingTalkDecorators("掌读")
 def zhangdu(start=None, end=None, new=None):
     if start is None:
         start = end = du.getNow()
@@ -121,13 +126,14 @@ def zhangdu(start=None, end=None, new=None):
         get_zd_order_task(start, end, account)
 
 
+@DingTalkDecorators("掌中云")
 def zhangzhongyun(start=None, end=None, new=None):
     if start is None:
         start = du.getNow()
         end = du.get_n_days(1)
 
     executor = ThreadPoolExecutor(max_workers=5)
-    accounts = get_account("掌中云") if new is None else get_new_account('掌中云')
+    accounts = get_account("掌中云")
     if len(accounts) == 0:
         return
     else:
@@ -137,6 +143,7 @@ def zhangzhongyun(start=None, end=None, new=None):
     executor.shutdown()
 
 
+@DingTalkDecorators("阅文")
 def yueweng(start=None, end=None):
     if start is None:
         start = end = du.getNow()
@@ -152,6 +159,7 @@ def yueweng(start=None, end=None):
     executor.shutdown()
 
 
+@DingTalkDecorators("七悦有声")
 def qiyueyousheng(start=None, end=None):
     if start is None:
         start = end = du.getNow()
@@ -164,6 +172,7 @@ def qiyueyousheng(start=None, end=None):
         AudioQiyue().get_order(start, end, account)
 
 
+@DingTalkDecorators("悠书阁")
 def youshuge(start=None, end=None):
     if start is None:
         start = end = du.getNow()
@@ -237,4 +246,5 @@ if __name__ == '__main__':
     # qiyue()
     # qiyueyousheng()
     # wending()
-    zhangdu()
+    # zhangdu()
+    zhangzhongyun()

+ 18 - 12
app/api_data/order_util.py

@@ -563,6 +563,7 @@ def get_zzy_channel_order(start, end, account, channel):
                 time.sleep(61)
                 print("掌中云接口调用sleep 61s...")
 
+        # print(response_result_json)
         if 'data' not in response_result_json.keys():
             print(f'掌中云账号【{key}】,查询时间【{start} - {end}】,渠道【{channel_name}】本次请求数据异常,响应报文【{r.text}】')
             break
@@ -570,28 +571,33 @@ def get_zzy_channel_order(start, end, account, channel):
         total_count = response_result_json['data']['count']  # 总数量
         order_item_list = response_result_json['data']['items']  # 订单列表
 
-        for order_item in order_item_list:
+        for i in order_item_list:
 
-            order_time = DateUtils.str_to_date_str(order_item['created_at'], "%Y-%m-%dT%H:%M:%S+08:00", "%Y-%m-%d %H:%M:%S")
-            order = (
-                DateUtils.str_to_stamp(order_time[:10]),
+
+            order_time = DateUtils.str_to_date_str(i['created_at'], "%Y-%m-%dT%H:%M:%S+08:00", "%Y-%m-%d %H:%M:%S")
+            reg_time = DateUtils.str_to_date_str(i['member']['created_at'], "%Y-%m-%dT%H:%M:%S+08:00", "%Y-%m-%d %H:%M:%S")
+
+            order_list.append((
+                order_time[:10],
                 stage,
                 '掌中云',
                 channel_name,
                 channel_id,
-                str(order_item['member']['openid']),
-                order_item['created_at'],
-                order_item['member']['created_at'],
-                round(order_item['price'] / 100, 2),
-                order_item['from_novel']['title'] if str(order_item['from_novel_id']) != 'None' else '',
-                str(order_item['id'])
-            )
-            order_list.append(order)
+                i['member']['openid'],
+                order_time,
+                reg_time,
+                round(i['price'] / 100, 2),
+                i['from_novel']['title'] if str(i['from_novel_id']) != 'None' else '',
+                str(i['id']),
+                2 if i['status'] == 1 else 1
+            ))
+
 
         if int(page) >= math.ceil(total_count / int(per_page)):
             break
         page = int(page) + 1
     # print(f"{channel_name}获取订单:{order_list.__len__()}")
+    # print(order_list)
     return order_list
 
 

+ 41 - 7
app/api_data/tg.py

@@ -1,10 +1,10 @@
-from model.DataBaseUtils import MysqlUtils
-db=MysqlUtils()
-with open('./zhangdu_account_config.csv','r',encoding='utf-8') as f:
-    # print(f.readlines())
-    for i in f.readlines():
-        a=  i.replace('\n','')
-        db.quchen_text.execute(f"insert into order_account_text(platform,text) values('掌读','{a}')")
+# from model.DataBaseUtils import MysqlUtils
+# db=MysqlUtils()
+# with open('./zhangdu_account_config.csv','r',encoding='utf-8') as f:
+#     # print(f.readlines())
+#     for i in f.readlines():
+#         a=  i.replace('\n','')
+#         db.quchen_text.execute(f"insert into order_account_text(platform,text) values('掌读','{a}')")
 
 
 # a={'x':11,'y11':2}
@@ -17,3 +17,37 @@ with open('./zhangdu_account_config.csv','r',encoding='utf-8') as f:
 # print(dict(zip(a,b)))
 # get
 
+
+
+def zsq(func):
+    def x(*args,**kwargs):
+
+        try:
+            func(*args,**kwargs)
+        except Exception as e:
+            print(e)
+
+
+    return x
+
+
+def zsq2(info):
+    def wrapper(func):
+        def deco(*args, **kwargs):
+            try:
+                func(*args, **kwargs)
+            except Exception as e:
+                print(info, e)
+
+        return deco
+
+    return wrapper
+
+
+@zsq2("趣程")
+def a(p,q):
+    print(p/q)
+
+
+if __name__ == '__main__':
+    a(2,0)

+ 17 - 1
model/DingTalkUtils.py

@@ -40,9 +40,25 @@ class DingTalkUtils:
         requests.post(url=url, headers=headers, json=data)
 
 
+# 钉钉报警装饰器
+def DingTalkDecorators(msg):
+    def wrapper(func):
+        def deco(*args, **kwargs):
+            try:
+                func(*args, **kwargs)
+            except Exception as e:
+                DingTalkUtils.send(msg+"->运行出错: "+str(e))
+
+        return deco
+    return wrapper
+
+@DingTalkDecorators("装饰器测试")
+def test():
+    print(3/0)
 
 if __name__ == '__main__':
-    DingTalkUtils.send("该下班了","13726204048,11")
+    # DingTalkUtils.send("该下班了","13726204048,11")
     # 发送的内容得加上趣程
+    test()