Browse Source

add notify individual

aaron-1015 3 years ago
parent
commit
bbf1de9d4c
1 changed files with 11 additions and 0 deletions
  1. 11 0
      api/main.py

+ 11 - 0
api/main.py

@@ -371,6 +371,14 @@ 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']
     for gid in glist:
@@ -429,6 +437,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
             os.remove(tmp_video_dir+top1['name_hash']+'.mp4')
             vid_duration = VideoFileClip(video_dest+top1['name_hash']+'.mp4').duration
             user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
+            line_token = user_obj['line_token']         # aa
             left_time = user_obj['left_time']
             email = user_obj['email']
             print('left_time is '+str(left_time))
@@ -439,10 +448,12 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
                 print(msg)
                 msg =msg.encode(encoding='utf-8')
                 mailer.send(msg, email)
+                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)+';')
                 notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
+                notify_line_user(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4", line_token)
         #except:
             #print('video generation error')
             #notify_group('影片錯誤')