This commit is contained in:
parent
1930dfc099
commit
6f21dad393
@ -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
23
vreader/api/__init__.py
Normal 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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user