This commit is contained in:
parent
1930dfc099
commit
2417563970
@ -1,3 +1,2 @@
|
|||||||
recursive-include vreader/api *.py
|
|
||||||
recursive-include vreader/templates *
|
recursive-include vreader/templates *
|
||||||
recursive-include vreader/static *
|
recursive-include vreader/static *
|
||||||
|
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 Blueprint
|
||||||
from flask import make_response, render_template, send_from_directory
|
from flask import make_response, render_template, send_from_directory
|
||||||
from html_sanitizer import Sanitizer
|
from html_sanitizer import Sanitizer
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
from vreader.config import Config
|
from vreader.config import Config
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint("common", __name__)
|
bp = Blueprint("common", __name__)
|
||||||
@ -63,25 +65,3 @@ def article_item(id):
|
|||||||
return make_response(
|
return make_response(
|
||||||
render_template("error.html", status=404, message=e)
|
render_template("error.html", status=404, message=e)
|
||||||
), 404
|
), 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 os
|
||||||
|
import vreader
|
||||||
|
|
||||||
|
from . import find_article
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import path
|
|
||||||
from flask import Blueprint, request
|
from flask import Blueprint, request
|
||||||
from vreader.config import Config
|
from vreader.config import Config
|
||||||
import vreader
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint("v1", __name__, url_prefix="/api/v1")
|
bp = Blueprint("v1", __name__, url_prefix="/api/v1")
|
||||||
@ -40,7 +41,7 @@ def generate():
|
|||||||
|
|
||||||
# Derive Filename
|
# Derive Filename
|
||||||
new_title = f"{date}_{video}_{title}"
|
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
|
# Write File
|
||||||
file = open(filepath, 'w', encoding='utf-8')
|
file = open(filepath, 'w', encoding='utf-8')
|
||||||
@ -48,25 +49,3 @@ def generate():
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
return { "title": resp["title"] }
|
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