From 83f79a0d4a0dcbc62ae5794436ef5fad766e2b9f Mon Sep 17 00:00:00 2001 From: Salt Date: Tue, 3 Mar 2020 20:08:14 -0600 Subject: [PATCH] Parse out flags, mock like we're actuall downloading things --- badwitch.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/badwitch.py b/badwitch.py index c94ebfd..319c40b 100755 --- a/badwitch.py +++ b/badwitch.py @@ -12,6 +12,7 @@ from appdirs import AppDirs from pathlib import Path import argparse import json +import logging import sys class Library: @@ -34,9 +35,18 @@ class Library: json.dump(self.albums, libfd, indent='\t') return - def download(self): - for album in self.albums: - return + def validate(self): + self.load() + + # Download library + def download(self, album=None): + if album is not None: + print('Downloading album: ' + album) + else: + print('Downloading entire library') + for album, albumcontent in self.albums.items(): + for song, songcontent in albumcontent.items(): + logging.info('Downloaded song: ' + song + ' by ' + songcontent['artist']) class BadWitch: # Our program @@ -48,6 +58,8 @@ class BadWitch: help='Override default library file with this one') self.argparser.add_argument('-v', '--verbose', action='store_true', help='Show more status messages') + self.argparser.add_argument('-d', '--debug', action='store_true', + help='Show even more status messages') self.argparser.add_argument('action', metavar='action', nargs='?', choices=['download', 'list', 'test'], help='Action to perform on the library') @@ -57,11 +69,18 @@ class BadWitch: def execute(self): self.args = self.argparser.parse_args() + # Parse flags + if self.args.debug: + logging.basicConfig(level=logging.DEBUG) + elif self.args.verbose: + logging.basicConfig(level=logging.INFO) # Initialize library libfile = self.args.library or self.dirs.user_data_dir + '/lib.json' lib = Library(file=libfile) # Perform action if self.args.action == 'download': + lib.load() + lib.download() return elif self.args.action == 'list': lib.load()