Update Exploring Near Earth Objects project and add Meme Generator project
This commit is contained in:
24
Meme_Generator/QuoteEngine/CSVIngestor.py
Normal file
24
Meme_Generator/QuoteEngine/CSVIngestor.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Module for ingesting CSV files containing quotes."""
|
||||
|
||||
from typing import List
|
||||
from .IngestorInterface import IngestorInterface
|
||||
from .QuoteModel import QuoteModel
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class CSVIngestor(IngestorInterface):
|
||||
"""Subclass for ingesting CSV files."""
|
||||
|
||||
allowed_extensions = ["csv"]
|
||||
|
||||
@classmethod
|
||||
def parse(cls, path: str) -> List[QuoteModel]:
|
||||
"""Parse the CSV file to extract quotes."""
|
||||
if not cls.can_ingest(path):
|
||||
raise Exception("Invalid ingest path")
|
||||
quotes = []
|
||||
df = pd.read_csv(path, header=0, sep=",", names=["body", "author"])
|
||||
for _, row in df.iterrows():
|
||||
quotes.append(QuoteModel(row["body"], row["author"]))
|
||||
return quotes
|
||||
Reference in New Issue
Block a user