Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from theonion/fix-migrate-channel-id-script
Browse files Browse the repository at this point in the history
Fix migrate channel id script
  • Loading branch information
mparent61 committed Mar 3, 2016
2 parents a23e3cb + 8ba93a0 commit e8fa6e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions videohub_client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Version 0.2.1

- Fix: `VidehubVideo` serialization flattens channel ID
- `migrate_channel_id` script fixes:
- `--check` mode OFF by default
- Better error handling, try all videos before failing

## Version 0.2.0

Expand Down
24 changes: 16 additions & 8 deletions videohub_client/management/commands/migrate_channel_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ def add_arguments(self, parser):
parser.add_argument(
'--check',
action='store_true',
default=True,
default=False,
help='Read-only check (preview) mode')

def handle(self, *args, **options):

# If any video fails, continue trying the rest before we raise error
failed = []
for video in VideohubVideo.objects.filter(channel_id__isnull=True):

url = video.get_api_url()
Expand All @@ -36,16 +38,22 @@ def handle(self, *args, **options):

if resp.ok:
channel = resp.json()['channel']
print('{} {} --> {} {}'.format(video.id,
video.title.strip().encode('utf-8'),
channel['id'],
channel['name'].encode('utf-8')
))
print('[{}] {} --> [{}] {}'.format(video.id,
video.title.strip().encode('utf-8')[:50],
channel['id'],
channel['name'].encode('utf-8')
))
if not options['check']:
video.channel_id = channel['id']
video.save()
else:
raise CommandError('Video request failed: {} --> {} {}'.format(
self.stderr.write(self.style.ERROR('Video request failed: {} --> {} {}'.format(
url,
resp.status_code,
resp.reason))
resp.reason)))
failed.append(video)

if failed:
raise CommandError('Failed to update {} video(s): {}'.format(
len(failed),
[f.id for f in failed]))

0 comments on commit e8fa6e1

Please sign in to comment.