From 5a3afd0bfa38e81b300a780c27b5604d3dc0b178 Mon Sep 17 00:00:00 2001 From: coolneng Date: Sat, 31 Oct 2020 14:04:52 +0100 Subject: [PATCH] Implement CSV reader --- .gitignore | 1 + src/database.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/database.py diff --git a/.gitignore b/.gitignore index c9fd099..510cfd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ src/constants.py +data diff --git a/src/database.py b/src/database.py new file mode 100644 index 0000000..7b5ba78 --- /dev/null +++ b/src/database.py @@ -0,0 +1,15 @@ +from csv import DictReader + + +def find_user(reader, id): + for row in reader: + if row["numero_de_documento"] == id or row["correo_institucional"] == id: + return row + raise Exception("Error: User not found") + + +def search_csv(filepath, id): + with open(filepath) as csvfile: + reader = DictReader(csvfile) + user = find_user(reader, id) + return user