Spaces:
Sleeping
Sleeping
Add slack notifications
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pandas as pd
|
|
| 5 |
from bson import ObjectId
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import requests
|
|
|
|
| 8 |
from collections import defaultdict
|
| 9 |
|
| 10 |
load_dotenv()
|
|
@@ -49,6 +50,45 @@ language_maps = {
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def get_translators(platform):
|
| 53 |
if platform == "dev":
|
| 54 |
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
|
@@ -339,6 +379,7 @@ def assign_translator(platform, translator, video):
|
|
| 339 |
}
|
| 340 |
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 341 |
if str(response.status_code).startswith('2'):
|
|
|
|
| 342 |
return "Successfully assigned."
|
| 343 |
else:
|
| 344 |
return str(response.status_code)
|
|
@@ -358,6 +399,7 @@ def assign_qa(platform, qa, video):
|
|
| 358 |
}
|
| 359 |
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 360 |
if str(response.status_code).startswith('2'):
|
|
|
|
| 361 |
return "Successfully assigned."
|
| 362 |
else:
|
| 363 |
return str(response.status_code)
|
|
|
|
| 5 |
from bson import ObjectId
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import requests
|
| 8 |
+
from datetime import timedelta
|
| 9 |
from collections import defaultdict
|
| 10 |
|
| 11 |
load_dotenv()
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
|
| 53 |
+
def print_slack(platform, video_id, translator_name, assignment="translator"):
|
| 54 |
+
if platform == "dev":
|
| 55 |
+
return
|
| 56 |
+
else:
|
| 57 |
+
client = pymongo.MongoClient(os.environ.get("MONGO_URI"))
|
| 58 |
+
source_db = client.deepsync_prod
|
| 59 |
+
|
| 60 |
+
headers = {
|
| 61 |
+
'Content-type': 'application/json',
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
video = source_db.dubbedvideos.find_one({"_id": ObjectId(video_id)})
|
| 65 |
+
video_name = video['title']
|
| 66 |
+
source_language = language_maps[video['sourceLanguage'][:2]]
|
| 67 |
+
target_language = language_maps[video['targetLanguage'][:2]]
|
| 68 |
+
video_duration = str(timedelta(seconds=video['duration']))
|
| 69 |
+
translator_details = "/".join(translator_name.split("/")[:3])
|
| 70 |
+
|
| 71 |
+
message = f"""```Platform : {platform}
|
| 72 |
+
{'Translator' if assignment == 'translator' else 'QA'} Assigned
|
| 73 |
+
Video Name : {video_name}
|
| 74 |
+
Source Language : {source_language}
|
| 75 |
+
Target Language : {target_language}
|
| 76 |
+
Video Duration : {video_duration} hours
|
| 77 |
+
Details : {translator_details}
|
| 78 |
+
```
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
json_data = {
|
| 82 |
+
'text': message,
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
response = requests.post(
|
| 86 |
+
os.environ.get('SLACK_WEBHOOK'),
|
| 87 |
+
headers=headers,
|
| 88 |
+
json=json_data,
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
def get_translators(platform):
|
| 93 |
if platform == "dev":
|
| 94 |
api_url = "https://api.dev-env.deepsync.co/api/v1"
|
|
|
|
| 379 |
}
|
| 380 |
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 381 |
if str(response.status_code).startswith('2'):
|
| 382 |
+
print_slack(platform, video_id, translator, "translator")
|
| 383 |
return "Successfully assigned."
|
| 384 |
else:
|
| 385 |
return str(response.status_code)
|
|
|
|
| 399 |
}
|
| 400 |
response = requests.post(f"{api_url}/dashboard/dubbed/video/assign/{role}", json=data, headers=HEADERS)
|
| 401 |
if str(response.status_code).startswith('2'):
|
| 402 |
+
print_slack(platform, video_id, qa, "qa")
|
| 403 |
return "Successfully assigned."
|
| 404 |
else:
|
| 405 |
return str(response.status_code)
|