VReader/vreader/api/__init__.py
Evan Reichard 6f21dad393
All checks were successful
continuous-integration/drone/push Build is passing
[fix] slight refactor
2023-11-12 16:09:56 -05:00

24 lines
598 B
Python

import os
from vreader.config import Config
def find_article(id):
directory = str(Config.DATA_PATH)
files = os.listdir(directory)
# Find Filename
filename = next((x for x in files if x[15:26] == id and x.endswith(".md")), None)
if filename is None:
return None
# Normalize File Info
return get_article_metadata(filename, directory)
def get_article_metadata(filename, directory):
return {
"date": filename[:14],
"video_id": filename[15:26],
"title": filename[27:][:-3],
"filepath": os.path.join(directory, filename)
}