瀏覽代碼

fix notify twice bug

ming 3 年之前
父節點
當前提交
e64de2f4c8
共有 3 個文件被更改,包括 11 次插入24 次删除
  1. 2 2
      OpenshotService/openshot_video_generator.py
  2. 1 4
      api/mailer.py
  3. 8 18
      api/main.py

+ 2 - 2
OpenshotService/openshot_video_generator.py

@@ -643,7 +643,7 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
         f=t.GetFrame(n)
         w.WriteFrame(f)
         
-    notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
+    #notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
     t.Close()
     w.Close()
     print("video at : www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
@@ -782,7 +782,7 @@ def anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
         f=t.GetFrame(n)
         w.WriteFrame(f)
         
-    notify_group(name+"(ENG)的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
+    #notify_group(name+"(ENG)的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
     t.Close()
     w.Close()
     print("video at : www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")

+ 1 - 4
api/mailer.py

@@ -13,10 +13,7 @@ gmail_password='lzpxinencaawsjus'
 sent_from = gmail_user
 #to = ['jared@choozmo.com','nina.huang@choozmo.com','ana@choozmo.com','ming@choozmo.com','mike@choozmo.com','andy@choozmo.com','hana@choozmo.com','stacy@choozmo.com','wen@choozmo.com','yukyo@choozmo.com','fxp87257@gmail.com','noodlesloves@gmail.com']
 
-
-
-
-def send(msg_in,email):
+def send_left_not_enough(msg_in,email):
     to = [email]
     msg = MIMEMultipart()
     msg['Subject'] = 'AI Spokesgirl 服務餘額不足 '

+ 8 - 18
api/main.py

@@ -474,23 +474,11 @@ def get_url_type(url):
     contentType = r.getheader('Content-Type')
     return contentType
 
-def notify_line_user(msg, line_token):
-    headers = {
-            "Authorization": "Bearer " + line_token,
-            "Content-Type": "application/x-www-form-urlencoded"
-    }
-    params = {"message": msg}   
-    r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
-
 def notify_group(msg):
-    glist=['WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD']
+    glist=['7vilzohcyQMPLfAMRloUawiTV4vtusZhxv8Czo7AJX8','WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD','1dbtJHbWVbrooXmQqc4r8OyRWDryjD4TMJ6DiDsdgsX','HOB1kVNgIb81tTB4Ort1BfhVp9GFo6NlToMQg88vEhh']
     for gid in glist:
-        headers = {
-                "Authorization": "Bearer " + gid,
-                "Content-Type": "application/x-www-form-urlencoded"
-        }
-        params = {"message": msg}   
-        r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+        headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
+        r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
 
 
 def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLang,video_id,user_id):
@@ -537,7 +525,7 @@ def gen_video_long_queue(name_hash,name,text_content, image_urls,avatar,multiLan
                 msg = '您本月額度剩下'+str(left_time)+'秒,此部影片有'+str(vid_duration)+'秒, 若要繼續產生影片請至 192.168.1.106:8887/confirm_add_value?name_hash='+name_hash+' 加值'
                 print(msg)
                 msg =msg.encode(encoding='utf-8')
-                mailer.send(msg, email)
+                mailer.send_left_not_enough(msg, email)
                 #notify_line_user(msg, line_token)
                 notify_group(name+":帳號餘額不足,請至email查看詳細資訊")
             else:
@@ -596,8 +584,9 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
                 msg = '您本月額度剩下'+str(left_time)+'秒,此部影片有'+str(vid_duration)+'秒, 若要繼續產生影片請至 192.168.1.106:8887/confirm_add_value?name_hash='+name_hash+' 加值'
                 print(msg)
                 msg =msg.encode(encoding='utf-8')
-                mailer.send(msg, email)
-                notify_line_user(msg, line_token)
+                mailer.send_left_not_enough(msg, email)
+                notify_group(msg)
+                #notify_line_user(msg, line_token)
             else:
                 left_time = left_time - vid_duration
                 db.query('UPDATE users SET left_time ='+str(left_time)+' WHERE id='+str(user_id)+';')
@@ -642,6 +631,7 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
             my_answer = remote_svc.call_video_eng(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['subtitles'].split(','),top1['avatar']) # method call
             shutil.copy(tmp_video_dir+top1['name_hash']+'.mp4',video_dest+top1['name_hash']+'.mp4')
             os.remove(tmp_video_dir+top1['name_hash']+'.mp4')
+            notify_group(name+"(ENG)的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
         except:
             print('video generation error')
             notify_group('影片錯誤')