Created
January 20, 2017 03:04
-
-
Save badboy99tw/5059695c4f9692a707327242a684ffc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import subprocess | |
| import os | |
| import click | |
| @click.command() | |
| @click.option('-s', '--source') | |
| @click.option('-t', '--target') | |
| @click.option('-r', '--episode_range', nargs=2, type=int, default=(1, 1)) | |
| @click.option('--run', is_flag=True, default=False) | |
| @click.option('--check_source', is_flag=True) | |
| @click.option('--check_title') | |
| @click.option('--offset', default=0, type=int) | |
| def upload(source, target, episode_range, run, check_source, check_title, offset): | |
| assert os.path.splitext(source)[-1] == os.path.splitext(target)[-1] | |
| for eid in range(episode_range[0], episode_range[1] + 1): | |
| source_path = source % eid | |
| target_path = target % (eid + offset) | |
| cp_cmd = 'aws s3 cp "%s" "%s"' % (source_path, target_path) | |
| if check_title: | |
| country, title, filename = target_path.split('/')[4:] | |
| country_code = country.split('-')[0] | |
| title_id_from_title = title.split('-')[0] | |
| title_id_from_filename = filename.split('_')[0][1:] | |
| assert country_code == check_title[:2] | |
| assert title_id_from_title == check_title | |
| assert title_id_from_filename == check_title | |
| if check_source: | |
| check_cmd = 'aws s3 ls "%s"' % source_path | |
| subprocess.check_call(check_cmd, shell=True) | |
| else: | |
| print(cp_cmd) | |
| if run: | |
| subprocess.check_call(cp_cmd, shell=True) | |
| if __name__ == '__main__': | |
| upload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment