def generate_meme(path=None, body=None, author=None):
    """ Generate a meme given an path and a quote """
    if path is None:
        images_dir = "./_data/Photos/Dog/"
        images = []
        for root, dirs, files in os.walk(images_dir):
            images = [os.path.join(root, name) for name in files]

        img_path = random.choice(images)
    else:
        img_path = path

    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')
    path = meme.make_meme(img_path, quote.body, quote.author)
    return path
Exemplo n.º 2
0
def setup():
    # @TODO: need to fix txt and pdf
    # quote_files = ['./_data/DogQuotes/DogQuotesTXT.txt',
    #                './_data/DogQuotes/DogQuotesDOCX.docx',
    #                './_data/DogQuotes/DogQuotesPDF.pdf',
    #                './_data/DogQuotes/DogQuotesCSV.csv']

    quote_files = [
        './_data/DogQuotes/DogQuotesDOCX.docx',
        './_data/DogQuotes/DogQuotesCSV.csv'
    ]

    quotes = []
    for file in quote_files:
        try:
            quotes.extend(Ingestor.parse(file))
        except ValueError as error:
            print(f"ValueError: {error}")

    images_path = "./_data/photos/dog/"

    imgs = []
    for root, dir, files in os.walk(images_path):
        imgs = [os.path.join(root, name) for name in files]

    return quotes, imgs
Exemplo n.º 3
0
def generate_meme(path=None, body=None, author=None):
    """
    Generate a meme from the body, author with a path.

    Parameters
    ----------
    path: None
    body: None
    author: None

    Returns
    -------
    A path where the meme is created.
    """
    print(path)
    if path is None:
        images_dir = './_data/photos/dog/'
        images = []
        for root, dirs, files in os.walk(images_dir):
            image = [os.path.join(root, name) for name in files]

        img_path = random.choice(images)
    else:
        img_path = path

    if body is None:
        quote_files = [
            './_data/DogQuotes/DogQuotesCSV.csv',
            './_data/DogQuotes/DogQuotesDOCX.docx',
            './_data/DogQuotes/DogQuotesPDF.pdf',
            './_data/DogQuotes/DogQuotesTXT.txt'
        ]
        quotes = []

        for f in quote_files:
            quotes.extend(Ingestor.parse(f))

        quote = random.choice(quotes)

    else:
        if author is None:
            raise Exception('Author requiered if body is used')

        quote = QuoteModel(body, author)

    meme = MemeEngine('./tmp')
    path = meme.make_meme(img_path, quote.body, quote.author)

    return path
def setup():
    """ Load all resources """
    quote_files = [
        "./_data/DogQuotes/DogQuotesTXT.txt",
        "./_data/DogQuotes/DogQuotesDOCX.docx",
        "./_data/DogQuotes/DogQuotesPDF.pdf",
        "./_data/DogQuotes/DogQuotesCSV.csv"
    ]
    all_quotes = []
    for f in quote_files:
        try:
            all_quotes.extend(Ingestor.parse(f))
        except ValueError as error:
            print(f"ValueError: {error}")

    images_path = "./_data/Photos/Dog/"
    all_images = []
    for root, dirs, files in os.walk(images_path):
        all_images = [os.path.join(root, name) for name in files]
    return all_quotes, all_images
Exemplo n.º 5
0
from ingestors import Ingestor

quote_files = [
    './_data/DogQuotes/DogQuotesTXT.txt',
    './_data/DogQuotes/DogQuotesDOCX.docx',
    './_data/DogQuotes/DogQuotesPDF.pdf', './_data/DogQuotes/DogQuotesCSV.csv'
]

for f in quote_files:
    try:
        print(Ingestor.parse(f))
    except ValueError as error:
        print(f"ValueError: {error}")