Parse out flags, mock like we're actuall downloading things
This commit is contained in:
		
							
								
								
									
										25
									
								
								badwitch.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								badwitch.py
									
									
									
									
									
								
							| @@ -12,6 +12,7 @@ from appdirs import AppDirs | |||||||
| from pathlib import Path | from pathlib import Path | ||||||
| import argparse | import argparse | ||||||
| import json | import json | ||||||
|  | import logging | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| class Library: | class Library: | ||||||
| @@ -34,9 +35,18 @@ class Library: | |||||||
|             json.dump(self.albums, libfd, indent='\t') |             json.dump(self.albums, libfd, indent='\t') | ||||||
|         return |         return | ||||||
|  |  | ||||||
|     def download(self): |     def validate(self): | ||||||
|         for album in self.albums: |         self.load() | ||||||
|             return |  | ||||||
|  |     # 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: | class BadWitch: | ||||||
|     # Our program |     # Our program | ||||||
| @@ -48,6 +58,8 @@ class BadWitch: | |||||||
|                 help='Override default library file with this one') |                 help='Override default library file with this one') | ||||||
|         self.argparser.add_argument('-v', '--verbose', action='store_true', |         self.argparser.add_argument('-v', '--verbose', action='store_true', | ||||||
|                 help='Show more status messages') |                 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='?', |         self.argparser.add_argument('action', metavar='action', nargs='?', | ||||||
|                 choices=['download', 'list', 'test'], |                 choices=['download', 'list', 'test'], | ||||||
|                 help='Action to perform on the library') |                 help='Action to perform on the library') | ||||||
| @@ -57,11 +69,18 @@ class BadWitch: | |||||||
|  |  | ||||||
|     def execute(self): |     def execute(self): | ||||||
|         self.args = self.argparser.parse_args()  |         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 |         # Initialize library | ||||||
|         libfile = self.args.library or self.dirs.user_data_dir + '/lib.json' |         libfile = self.args.library or self.dirs.user_data_dir + '/lib.json' | ||||||
|         lib = Library(file=libfile) |         lib = Library(file=libfile) | ||||||
|         # Perform action |         # Perform action | ||||||
|         if self.args.action == 'download': |         if self.args.action == 'download': | ||||||
|  |             lib.load() | ||||||
|  |             lib.download() | ||||||
|             return |             return | ||||||
|         elif self.args.action == 'list': |         elif self.args.action == 'list': | ||||||
|             lib.load() |             lib.load() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user