[fix] slight refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Evan Reichard 2023-11-12 16:09:21 -05:00
parent 1930dfc099
commit 6f21dad393
4 changed files with 31 additions and 49 deletions

View File

@ -1,3 +1,3 @@
recursive-include vreader/api *.py
recursive-include vreader/templates *
recursive-include vreader/static *
recursive-include vreader/api *

23
vreader/api/__init__.py Normal file
View File

@ -0,0 +1,23 @@
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)
}

View File

@ -1,9 +1,11 @@
import os
from . import get_article_metadata, find_article
from flask import Blueprint
from flask import make_response, render_template, send_from_directory
from html_sanitizer import Sanitizer
from markdown import markdown
from vreader.config import Config
import os
bp = Blueprint("common", __name__)
@ -63,25 +65,3 @@ def article_item(id):
return make_response(
render_template("error.html", status=404, message=e)
), 404
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)
}

View File

@ -1,9 +1,10 @@
import os
import vreader
from . import find_article
from datetime import datetime
from os import path
from flask import Blueprint, request
from vreader.config import Config
import vreader
bp = Blueprint("v1", __name__, url_prefix="/api/v1")
@ -40,7 +41,7 @@ def generate():
# Derive Filename
new_title = f"{date}_{video}_{title}"
filepath = path.join(directory, f"{new_title}.md")
filepath = os.path.join(directory, f"{new_title}.md")
# Write File
file = open(filepath, 'w', encoding='utf-8')
@ -48,25 +49,3 @@ def generate():
file.close()
return { "title": resp["title"] }
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)
}