Example #1
0
 def save_article(cls, form):
     from models.chapter import Chapter
     article = Article.upsert({
         'chapter_id': int(form.get('chapter_id')),
     }, {
         'title': form.get('title'),
         'content': form.get('content'),
     })
     Chapter.upsert({
         'id': article.chapter_id,
     }, {
         'article_id': article.id,
     })
Example #2
0
def add():
    form = request.form
    if validate_legitimacy(form, request.cookies):
        query_form = {
            'id': int(form.get('id'))
        }
        update_form = {
            'subject_id': int(form.get('subject_id', -1)),
            'name': form.get('name', ''),
            'article_id': int(form.get('article_id')) if form.get('article_id') != '' else -1,
        }
        Chapter.upsert(query_form, update_form)
        return redirect(url_for('.index'))
    else:
        abort(403)
Example #3
0
def fetch_chapter(chapter_prefix, chapter):
    chapter_bsoup = get_soup(get_chapter_html(chapter_prefix, chapter))
    chapter_title = get_chapter_title(chapter_bsoup)
    chapter_content = get_chapter_content(chapter_bsoup)
    return Chapter(no=chapter, title=chapter_title, content=chapter_content)


# novels = fetch_all_novel("http://www.truyenngan.com.vn/truyen-ngan.html")
# for novel in novels:
#     # novel.print()
#     for chapter in novel.chapters:
#         chapter.print()
#     # print("--------------------------------------------------------")
# chapter = fetch_chapter("http://truyenfull.vn/truyen-than-khong-thien-ha", 1)
# chapter.print()

# def db_save_novel(novel_id):

# def db_save_chapter(novel_id, title, content, chapter):

# html = get_html("http://truyenfull.vn/pham-nhan-tu-tien", 333)
# soup = get_soup(html)
# title = get_chapter_title(soup)
# content = get_content(soup)
# print(title)
# print(content)

# html = get_novel_html("http://truyenfull.vn/truyen-than-khong-thien-ha/")
# soup = get_soup(html)
# print(get_novel_genre(soup))
Example #4
0
def fetch_all_novel(novel_list_url):
    soup = get_soup(get_html(novel_list_url))
    novels = []
    all_story_group = soup.find_all("div", "wrap-carousel-cate")
    for story_group_bsoup in all_story_group:
        story_bsoups = story_group_bsoup.find("ul").find_all("li")
        story_bsoup = story_bsoups[0]
        detail_link = "http://www.truyenngan.com.vn/" + story_bsoup.find(
            "div", "carousel-cate-img").a["href"]
        detail = get_soup(get_html(detail_link))
        image = story_bsoup.find("div", "carousel-cate-img").a.img["src"]
        title = story_bsoup.find("div", "carousel-cate-title").a.get_text()
        description = detail.find("strong").get_text()
        novel = Novel(title, "", description, image, "Truyện ngắn")
        novel.chapters = []
        novels.append(novel)

        no = 1
        for story_bsoup in story_bsoups:
            detail_link = "http://www.truyenngan.com.vn/" + story_bsoup.find(
                "div", "carousel-cate-img").a["href"]
            title = story_bsoup.find("div", "carousel-cate-title").a.get_text()
            detail = get_soup(get_html(detail_link))
            author = detail.find("div", "details-poster").a.strong.get_text()
            content = str(detail.find("div", "maincontent"))
            chapter = Chapter(no, title + " - " + author, content)
            novel.chapters.append(chapter)
            no += 1

    return novels
Example #5
0
def create_chapter(uid, name, mid):
    from models import db
    from models.user import User
    from models.manga import Manga
    from models.chapter import Chapter
    # check user privilege
    user = User.query.get(uid)
    if not user.privilege.operate_chapter:
        return 1
    # check manga existence
    manga = Manga.query.get(mid)
    if manga is None:
        return 2
    # create chapter
    new_chapter = Chapter(chapter_name=name, aff_mid=mid)
    db.session.add(new_chapter)
    db.session.commit()
    update_chapter(new_chapter)
    # create two default quests
    quest1_code = create_quest(uid, "翻译", "TRANSLATION", False,
                               new_chapter.cid)
    quest2_code = create_quest(uid,
                               "校对",
                               "PROOFREADING",
                               False,
                               new_chapter.cid,
                               isClosed=True)
    quest3_code = create_quest(uid,
                               "嵌字",
                               "TYPESETTING",
                               False,
                               new_chapter.cid,
                               isClosed=True)
    return 0
Example #6
0
def get_chapter_list():
    args = request.args
    chapter_list = []
    from models.chapter import Chapter
    chapters = Chapter.find_all(subject_id=int(args['subject_id']))
    for c in chapters:
        chapter_list.append(c.json())
    return Response(json.dumps(chapter_list), content_type='application/json')
 def __load_chapters(self, chapters_texts):
     if self.language not in self.pipeline:
         self.pipeline[self.language] = stanza.Pipeline(
             **DocumentParser.PIPELINE_CFG, lang=self.language)
     res = []
     for chapter_text in chapters_texts:
         title, text = chapter_text.split('\n', 1)
         model = self.pipeline[self.language](text)
         res.append(Chapter(model, title, self.language))
     return res
Example #8
0
def edit_chapter(chapter_id):
    c = Chapter.find(chapter_id)
    cookie = token_cookie()
    template = render_template(
        "chapter/edit_chapter.html",
        chapter=c,
        token=cookie['token'],
    )
    r = make_response(template)
    r.set_cookie(cookie['token'], cookie['id'], max_age=300)
    return r
Example #9
0
 def get_subject_and_chapter_name(self):
     obj = {}
     from models.subject import Subject
     from models.chapter import Chapter
     subjects = Subject.all()
     for s in subjects:
         clist = Chapter.find_all(subject_id=s.id)
         temp = []
         for c in clist:
             temp.append(c.__dict__)
         obj[s.id] = temp
     return obj
Example #10
0
 def add_problem_from_xls(cls, lists):
     from models.subject import Subject
     from models.chapter import Chapter
     subject = Subject.new({
         "name": lists[0][0],
     })
     chapter_id_flag = -1
     chapter_id = -1
     for item in lists:
         if int(item[1]) != chapter_id_flag:
             chapter = Chapter.new({
                 'subject_id': subject.id,
                 'name': item[2]
             })
             chapter_id = chapter.id
             chapter_id_flag = int(item[1])
         cls.add_problem(subject.id, chapter_id, item)
Example #11
0
def index():
    chapter_list = Chapter.all()
    return render_template("chapter/chapter.html", chapters=chapter_list)
Example #12
0
 def begin_new_chapter(self, chapter_number_str):
     chapter_number = int(chapter_number_str)
     if(self.current_chapter):
         self.current_book.add_chapter(self.current_chapter)
     self.current_chapter = Chapter(chapter_number)
Example #13
0
 def get_chapter_name(chapter_id):
     from models.chapter import Chapter
     return Chapter.find(chapter_id).name
Example #14
0
def get_chapter_list():
    form = json.loads(request.get_data(as_text=True))
    all_chapter = Chapter.find_all(subject_id=form["subject_id"])
    chapter_list = [c.__dict__ for c in all_chapter]
    return Response(json_util.dumps(chapter_list, ensure_ascii=False), content_type='application/json')
Example #15
0
 def get_chapter(self):
     from models.chapter import Chapter
     return Chapter.find(self.chapter_id)
 def parse_chapter(self, text, title=None):
     model = self.pipeline(text)
     return Chapter(model, title if title else self.chapter_title,
                    self.lang)