Update Exploring Near Earth Objects project and add Meme Generator project
This commit is contained in:
26
Meme_Generator/QuoteEngine/TextIngestor.py
Normal file
26
Meme_Generator/QuoteEngine/TextIngestor.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Module for ingesting text files containing quotes."""
|
||||
|
||||
from typing import List
|
||||
from .IngestorInterface import IngestorInterface
|
||||
from .QuoteModel import QuoteModel
|
||||
|
||||
|
||||
class TextIngestor(IngestorInterface):
|
||||
"""Subcalss for ingesting text files."""
|
||||
|
||||
allowed_extensions = ["txt"]
|
||||
|
||||
@classmethod
|
||||
def parse(cls, path: str) -> List[QuoteModel]:
|
||||
"""Parse the text file to extract quotes."""
|
||||
if not cls.can_ingest(path):
|
||||
raise Exception("Invalid ingest path")
|
||||
quotes = []
|
||||
with open(path, "r") as file:
|
||||
for line in file.readlines():
|
||||
line = line.strip()
|
||||
if line:
|
||||
parts = line.split(" - ", 1)
|
||||
if len(parts) == 2:
|
||||
quotes.append(QuoteModel(parts[0], parts[1]))
|
||||
return quotes
|
||||
Reference in New Issue
Block a user