-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added management command to fetch skills for videos
- Loading branch information
1 parent
b771d8b
commit 027d980
Showing
2 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
enterprise_catalog/apps/video_catalog/management/commands/fetch_video_skills.py
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,54 @@ | ||
""" | ||
Management command for fetching video skills from taxonomy connector | ||
""" | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from enterprise_catalog.apps.video_catalog.models import Video, VideoSkill | ||
from enterprise_catalog.apps.video_catalog.utils import store_video_skills | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Management command for fetching video skills from taxonomy connector | ||
Example Usage: | ||
>> python manage.py fetch_video_skills | ||
""" | ||
help = ( | ||
'Fetch the skills associated with videos from taxonomy connector' | ||
) | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--force', | ||
default=False, | ||
action='store_true', | ||
help='Force execution and re-process any previously processed rows.', | ||
) | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
Fetch video content metadata from LMS. | ||
""" | ||
processed_videos = VideoSkill.objects.all().values_list('video__edx_video_id', flat=True) | ||
videos = Video.objects.exclude(edx_video_id__in=processed_videos) | ||
if options.get('force', False): | ||
videos = Video.objects.all() | ||
for video in videos: | ||
try: | ||
store_video_skills(video) | ||
logger.info( | ||
'[FETCH_VIDEO_SKILLS] Skills for Video id: "%s" saved successfully.', | ||
video.edx_video_id | ||
) | ||
except Exception as ex: # pylint: disable=broad-exception-caught | ||
logger.error( | ||
'[FETCH_VIDEO_SKILLS] Skills for Video id: "%s" could not be fetched. Ex: "%s".', | ||
video.edx_video_id, | ||
str(ex) | ||
) |
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