def setup(): """ Load all resources """ quote_files = [ './_data/DogQuotes/DogQuotesTXT.txt', './_data/DogQuotes/DogQuotesDOCX.docx', './_data/DogQuotes/DogQuotesPDF.pdf', './_data/DogQuotes/DogQuotesCSV.csv' ] # TODO: Use the Ingestor class to parse all files in the # quote_files variable """Very similar implementation as meme file code""" """Variable for all quotes""" """For loop with try except calling Ingestor class parse""" """ to add quotes you need array""" quote = [] for i in quote_files: try: quote.extend(Ingestor.parse(i)) except ValueError as error: print(f"ValueError: {error}") images_path = "./_data/photos/dog/" # TODO: Use the pythons standard library os class to find all # images within the images images_path directory """For all images""" image = [] """For loop similar to meme.py applies format to image file to pull it""" for root, dirs, files in os.walk(images_path): image = [os.path.join(root, name) for name in files] return quote, image
def generate_meme(path=None, body=None, author=None): """ Generate a meme given an path and a quote """ """Not used error?""" """img = None """ """Not used error?""" """quote = None""" if path is None: images = "./_data/photos/dog/" imgs = [] for root, dirs, files in os.walk(images): imgs = [os.path.join(root, name) for name in files] img = random.choice(imgs) else: img = path[0] if body is None: quote_files = [ './_data/DogQuotes/DogQuotesTXT.txt', './_data/DogQuotes/DogQuotesDOCX.docx', './_data/DogQuotes/DogQuotesPDF.pdf', './_data/DogQuotes/DogQuotesCSV.csv' ] quotes = [] for f in quote_files: quotes.extend(Ingestor.parse(f)) quote = random.choice(quotes) else: if author is None: raise Exception('Author Required if Body is Used') quote = QuoteModel(body, author) meme = MemeEngine('./tmp') """Changed meme.make_meme to fit my coded function""" path = meme.format_and_make(img, quote.body, quote.author) return path
def test_parse_no_extension(self): with self.assertRaises(ValueError): _ = Ingestor.parse('fakefile')
def test_parse_fakefile(self): with self.assertRaises(FileNotFoundError): _ = Ingestor.parse('fakefile.pdf')