import argparse import json from podcast.models.api_podcast import ApiPodcast from podcast.models.api_episode import ApiEpisode from podcast import config def get_podcast(podcast_id, network_id): megaphone_api = ApiPodcast(network_id) return megaphone_api.get(podcast_id) def get_episode(podcast_id, episode_id, network_id): megaphone_api = ApiEpisode(network_id) return megaphone_api.get(podcast_id=podcast_id, episode_id=episode_id) def create_episode(podcast_id): megaphone_api = ApiEpisode() return megaphone_api.create(podcast_id=podcast_id, episode_data={ 'title': 'troy draft LARGE', 'pubdate': '2020-06-01T14:54:02.690Z', }) def create_podcast(): megaphone_api = ApiPodcast() return megaphone_api.create(podcast_data={ 'title': 'Slug Fest', 'slug': 'brand-new-show' }) def update_episode(podcast_id, episode_id): megaphone_api = ApiEpisode() return megaphone_api.update(podcast_id=podcast_id, episode_id=episode_id, data={ 'preCount': 1, 'insertionPoints': [12.12, 20.34] }) def main(): parser = argparse.ArgumentParser(prog='megaphone tester') parser.add_argument('-api_key', required=False, help='API Key') parser.add_argument('-api_url', required=False, help='API URL') parser.add_argument('-action', required=False, help='What API action') parser.add_argument('-podcast_id', required=False, help='podcast id') parser.add_argument('-episode_id', required=False, help='episode id') parser.add_argument('-network_id', required=False, help='network id') args = parser.parse_args() config.MEGAPHONE_API_TOKEN = args.api_key config.MEGAPHONE_API_URL = 'https://cms.megaphone.fm/api/networks/{}'.format(args.api_url) message = {} if args.action == 'get_podcast': message = get_podcast(args.podcast_id, args.network_id) if args.action == 'get_episode': message = get_episode(podcast_id=args.podcast_id, episode_id=args.episode_id) if args.action == 'create_episode': message = create_episode(podcast_id=args.podcast_id) if args.action == 'update_episode': message = update_episode(podcast_id=args.podcast_id, episode_id=args.episode_id) if args.action == 'create_podcast': message = create_podcast() print(json.dumps(message)) if __name__ == "__main__": main()