from flask import request, Blueprint from flask_restful import Resource, Api import logging from bs4 import BeautifulSoup from models.config import HOMEPAGE_DIR, ROOM_PLANNER_DIR from models.utils.parsers import get_section_parser, SectionParser from models.utils.validators import is_valid_section from models.utils import read_line_md, write_md manages_app = Blueprint('manages', __name__) api = Api(manages_app) logger = logging.getLogger(__name__) DIR = {'home': HOMEPAGE_DIR, 'room_planner': ROOM_PLANNER_DIR} class RequiredData(): def __init__(self): self.is_amp_img, self.is_amp_youtube = False, False def load(self, section_data, text): if '' in text: soup = BeautifulSoup(text, "html.parser") section_data.setdefault('a', []).append(soup.a.string) elif '
' in line: is_target_class_section = False content = section_parser.update(content, line) else: content += line if is_valid_section(request.args.get('section', type=str), line): is_target_class_section = True section_parser = get_section_parser( request.args.get('section', type=str))(request.json) write_md(DIR.get(request.args.get('page', type=str)), content) return {'content': content} api.add_resource(ManageData, '/api/manages/data')