Esempio n. 1
0
def set_index(chapter: Chapter, indexes: List[int], depth: int) -> List[int]:
	if len(indexes) < depth + 1:
		indexes.append(0)

	if has_verses(chapter):
		verse_local_index = 0
		for verse in chapter.verses:
			if verse.part_type == PartType.Hadith or verse.part_type == PartType.Verse:
				indexes[depth] = indexes[depth] + 1
				verse.index = indexes[depth]
				verse_local_index = verse_local_index + 1
				verse.local_index = verse_local_index
				verse.path = chapter.path + ":" + str(verse_local_index)
		chapter.verse_count = indexes[depth] - chapter.verse_start_index
	
	report_numbering = True
	sequence = None
	if has_chapters(chapter):
		chapter_local_index = 0
		for subchapter in chapter.chapters:
			indexes[depth] = indexes[depth] + 1
			subchapter.index = indexes[depth]
			chapter_local_index = chapter_local_index + 1
			subchapter.local_index = chapter_local_index
			subchapter.path = chapter.path + ":" + str(chapter_local_index)
			subchapter.verse_start_index = indexes[-1]

			if report_numbering and subchapter.part_type == PartType.Chapter:
				chapter_number_str = CHAPTER_TITLE_PATTERN.search(subchapter.titles['en'])
				if chapter_number_str:
					chapter_number = int(chapter_number_str.group(1))
					if sequence and sequence + 1 != chapter_number:
						error_msg = 'Chapter ' + str(chapter_local_index) + ' with indexes ' + str(indexes) + ' does not match title ' + str(subchapter.titles)
						print(error_msg)
						SEQUENCE_ERRORS.append(error_msg)
						# raise Exception('Chapter ' + str(chapter_local_index) + ' with indexes ' + str(indexes) + ' does not match title ' + str(subchapter.titles))
					sequence = chapter_number
					# if chapter_number != chapter_local_index:
						# print('Chapter ' + str(chapter_local_index) + ' with indexes ' + str(indexes) + ' does not match title ' + str(subchapter.titles))
						# report_numbering = False
						# raise Exception('Chapter ' + str(chapter_local_index) + ' with indexes ' + str(indexes) + ' does not match title ' + str(subchapter.titles))

			subchapter.crumbs = copy.copy(chapter.crumbs)
			crumb = Crumb()
			crumb.indexed_titles = {
				Language.EN.value: subchapter.part_type.name + ' ' + str(subchapter.local_index)
			}
			crumb.titles = subchapter.titles
			crumb.path = subchapter.path
			subchapter.crumbs.append(crumb)

			indexes = set_index(subchapter, indexes, depth + 1)
		chapter.verse_count = indexes[-1] - chapter.verse_start_index

	return indexes
Esempio n. 2
0
def build_chapters(file: str, verses: List[Verse],
                   verse_translations: List[Translation]) -> List[Chapter]:
    chapters: List[Chapter] = []

    quran = xml.etree.ElementTree.parse(file).getroot()

    suras = quran.find('suras')
    for s in suras.findall('sura'):
        meta = s.attrib
        index = int(meta['index'])
        ayas = int(meta['ayas'])
        start = int(meta['start'])
        name = meta['name']
        tname = meta['tname']
        ename = meta['ename']
        type = meta['type']
        order = int(meta['order'])
        rukus = int(meta['rukus'])

        titles = {
            Language.AR.value: name,
            Language.EN.value: ename,
            Language.ENT.value: tname
        }

        sura = Chapter()
        sura.part_type = PartType.Chapter
        sura.titles = titles
        sura.reveal_type = type
        sura.order = order
        sura.rukus = rukus
        sura.verses = verses[start:ayas + start]
        sura.verse_translations = verse_translations
        sura.default_verse_translation_ids = {
            "en": "en.qarai",
            "fa": "fa.makarem"
        }

        chapters.append(sura)

    sajdas = get_sajda_data(quran)
    for k, v in sajdas.items():
        (sura_index, aya_index) = k
        sajda_chapter = chapters[sura_index - 1]
        sajda_chapter.sajda_type = v
        sajda_chapter.verses[aya_index - 1].sajda_type = v

    # add_group_data(quran, ayaindex, 'juzs', 'juz')
    # add_group_data(quran, ayaindex, 'hizbs', 'quarter')
    # add_group_data(quran, ayaindex, 'manzils', 'manzil')
    # add_group_data(quran, ayaindex, 'rukus', 'ruku')
    # add_group_data(quran, ayaindex, 'pages', 'page')

    return chapters
Esempio n. 3
0
def addChapterComplete():
    subject_id = request.form['subject_id']
    form = ChapterForm()
    name = form.name.data
    db.session.add(Chapter(name=name, subject_id=subject_id))
    db.session.commit()
    message = '添加成功'
    return render_template('ques/message.html', message=message)
Esempio n. 4
0
def create_chapter(gameid):
    game = Game.query.get_or_404(gameid)
    if not game.can_edit(current_user):
        flash('Naughty!')
        return redirect(url_for('front.index'))
    form = CreateChapterForm()
    if form.validate_on_submit():
        c = Chapter(name=form.chapter_name.data, game=game)
        s = Scene(name=form.scene_name.data, chapter=c)
        db.session.add_all([c, s])
        if form.make_current:
            game.current_chapter = c
        c.ensure_has_current()
        db.session.commit()
        set_currents(int(gameid))
        return redirect(url_for('game.game', gameid=gameid))
    return render_template('game/create_chapter.html', form=form, game=game)
Esempio n. 5
0
 def setUp(self):
     self.user = User(email='*****@*****.**',
                      username='******',
                      password='******')
     self.dictionary = Dictionary(user=self.user,
                                  native_lang='spanish',
                                  foreign_lang='english')
     self.chapter = Chapter(dictionary=self.dictionary, chapter_name='food')
     super().setUp()
def create_chapter(title_ar) -> Chapter:
    chapter = {
        'part_type': PartType.Chapter.value,
        'titles': {
            'ar': title_ar
        },
        'verse_translations': [],
        'verses': []
    }
    return Chapter(**chapter)
Esempio n. 7
0
def chapter(gameid, chapterid):
    game = Game.query.get_or_404(gameid)
    chapter = Chapter.query.get_or_404(chapterid)
    if not chapter.can_edit(current_user):
        flash('Naughty!')
        return redirect(url_for('front.index'))
    form = EditChapterForm()
    dform = ConfirmDeleteForm()
    if form.submit.data and form.validate_on_submit():
        chapter.name = form.chapter_name.data
        if form.make_current:
            game.current_chapter = chapter
            chapter.ensure_has_current()
            db.session.commit()
            set_currents(int(gameid))
        else:
            db.session.commit()
        return redirect(url_for('game.game', gameid=gameid))
    elif dform.delete.data and dform.validate_on_submit():
        chapter.empty()
        db.session.delete(chapter)
        if len(game.chapters) == 0:
            c = Chapter(name="1", game=game)
            db.session.add(c)
            game.current_chapter = c
            s = Scene(name="1", chapter=c)
            db.session.add(s)
            c.current_scene = s
        db.session.commit()
        set_currents(int(gameid))
        return redirect(url_for('game.game', gameid=gameid))
    else:
        form.chapter_name.data = chapter.name
        form.make_current.data = chapter.is_current
        dform.confirm.data = False
    return render_template('game/chapter.html',
                           form=form,
                           dform=dform,
                           game=game,
                           chapter=chapter)
Esempio n. 8
0
    def post(self, dictionary_id):
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        chapter = Chapter.query.filter_by(id=json_data['id']).first()
        if chapter:
            return {'message': 'Chapter already exists'}, 400
        chapter = Chapter(dictionary=dictionary_id,
                          chapter_name=json_data['chapter_name'])

        db.session.add(chapter)
        db.session.commit()
        result = chapter_schema.dump(chapter).data
        return {"status": 'success', 'data': result}, 201
Esempio n. 9
0
def addChapter():
    form = ChapterForm()

    subject_list = Subject.query.all()
    if form.validate_on_submit():
        subject_id = request.form['subject_id']
        form = ChapterForm()
        name = form.name.data
        db.session.add(Chapter(name=name, subject_id=subject_id))
        db.session.commit()
        message = '添加成功'
        return render_template('ques/message.html', message=message)

    return render_template('ques/addChapter.html',
                           form=form,
                           subject_list=subject_list)
Esempio n. 10
0
def build_volume(file,
                 title_en: str,
                 title_ar: str,
                 description: str,
                 last_volume: bool = False) -> Chapter:
    volume = Chapter()
    volume.titles = {Language.EN.value: title_en, Language.AR.value: title_ar}
    volume.descriptions = {Language.EN.value: [description]}
    if last_volume:
        volume.chapters = build_hubeali_book_8(file)
    else:
        volume.chapters = build_hubeali_books(file)
    volume.part_type = PartType.Volume

    return volume
Esempio n. 11
0
def create_game():
    form = CreateGameForm()
    if form.validate_on_submit():
        game = Game(name=form.game_name.data,
                    owner=current_user,
                    blurb=form.blurb.data,
                    player_max=form.get_player_max())
        game.set_password(form.password.data)
        chapter = Chapter(name=form.chapter_name.data, game=game)
        scene = Scene(name=form.chapter_name.data, chapter=chapter)
        db.session.add_all([game, chapter, scene])
        game.ensure_has_current()
        db.session.commit()
        set_currents(int(game.id))
        flash('Congratulations, you created a game called "{}"!'.format(
            game.name))
        return redirect(url_for('game.game', gameid=game.id))
    return render_template('game/create_game.html', form=form)
Esempio n. 12
0
def add_chapter(title_id):
    title = Title.query.filter_by(id=title_id).first_or_404()
    chapter = Chapter(title_id=title.id)
    form = EditChapterForm()
    if form.validate_on_submit():
        chapter.chapter_name = form.chapter_name.data
        chapter.chapter_number = form.chapter_number.data
        chapter.poster_url = form.poster_url.data
        chapter.read_url = form.read_url.data
        db.session.add(chapter)
        db.session.commit()
        return redirect(url_for('chapter', chapter_id=chapter.id))
    return render_template('edit_chapter.html', title='add chapter', form=form)
Esempio n. 13
0
def update_novel(name):
    """更新文章"""
    novel_url = get_novel(name)
    name, author = get_novel_info(novel_url)
    novel = Novel.query.filter_by(name=name).first()
    if not novel:
        logging.info('添加文章')
        novel = Novel(name=name, author=author)
        db.session.add(novel)
    print(novel.id)
    chapters = get_novel_chapters(novel_url)
    all_chapters = []
    for _ in chapters:
        title, chapter_url = _
        try:
            chapter = re.findall(r'\d{1,}', title)[0] if re.findall(
                r'\d{1,}', title) else getResultForDigit(
                    title.split()[0].replace('第', '').replace('章', ''))
        except Exception as e:
            logging.info(e)
        else:
            all_chapters.append((name, chapter, title, chapter_url))
            logging.info(chapter, title, chapter_url)
            # novel = Novel.query.filter(Novel.name.contains(name)).first()
            # novel = Novel.query.filter(Novel.name==name).first()
            logging.warning(novel.id)
            new_chapter = Chapter.query.filter(
                Chapter.chapter == chapter,
                Chapter.novel_id == novel.id).first()
            logging.warning(new_chapter)
            # logging.info('chapter:', new_chapter)
            if not new_chapter:
                logging.warning('添加章节')
                content = get_chapter_content(chapter_url).strip()
                new_chapter = Chapter(title=title,
                                      chapter=chapter,
                                      content=content,
                                      novel_id=novel.id)
                db.session.add(new_chapter)
Esempio n. 14
0
File: routes.py Progetto: KOPACb/iss
def add_chapter():
    user = current_user
    raw_files = File.query.filter_by()
    raw_formulas = Formula.query.filter_by()
    files = []
    for file in raw_files:
        files.append((file.id, file.filename))
    formulas = []
    for formula in raw_formulas:
        formulas.append((formula.id, formula.name))
    form = ChapterForm()
    form.files.choices = files
    form.files.default = ''
    form.formulas.choices = formulas
    form.formulas.default = ''
    #    form.files.coerce='int'
    if form.validate_on_submit():
        #        for item in form:
        #            print(item.data)
        #        print(form.files.data)
        chapter = Chapter(name=form.name.data,
                          short_description=form.short_description.data,
                          description=form.description.data,
                          user_id=user.id)
        if form.files.data:
            for f in form.files.data:
                print(type(f))
                file = File.query.filter_by(id=int(f)).first_or_404()
                print(file)
                chapter.files.append(file)
        db.session.add(chapter)
        db.session.commit()
        print(form.files.data)
        return redirect(url_for('chapters'))
    return render_template('edit_chapter.html',
                           title='Add chappter',
                           user=user,
                           form=form)
Esempio n. 15
0
            db.session.add(te)
        if a_translation_id and a_example_id:
            s = asoc_translation_example.insert().values(
                translation_id=a_translation_id, example_id=a_example_id)
            db.session.execute(s)

with open('csv/tbl_chapter.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file, delimiter=',')
    for row in csv_reader:
        c_id = row['id']
        c_number = row['number']
        c_name = row['name']
        c_book_id = row['book_id']
        if c_id and c_number and c_name and c_book_id:
            c = Chapter(id=c_id,
                        number=c_number,
                        name=c_name,
                        book_id=c_book_id)
            db.session.add(c)

with open('csv/tbl_book.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file, delimiter=',')
    for row in csv_reader:
        b_id = row['id']
        b_name = row['name']
        b_short_name = row['short_name']
        if b_id and b_name and b_short_name:
            b = Book(id=b_id, name=b_name, short_name=b_short_name)
            db.session.add(b)

with open('csv/tbl_grammatical_term.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file, delimiter=',')
def load_chapter_from_file(filename):
    filepath = os.path.join(os.path.dirname(__file__), filename)
    with open(filepath, 'r', encoding='utf8') as qfile:
        file_content = qfile.read()
        file_json = json.loads(file_content)
        return Chapter(**file_json['data'])
Esempio n. 17
0
def build_kafi() -> Chapter:
    kafi = Chapter()
    kafi.index = BOOK_INDEX
    kafi.path = BOOK_PATH
    kafi.titles = {Language.EN.value: "Al-Kafi", Language.AR.value: "الكافي"}
    kafi.descriptions = {
        Language.EN.value: [
            "Of the majestic narrator and the scholar, the jurist, the Sheykh Muhammad Bin Yaqoub Al-Kulayni Well known as ‘The trustworthy of Al-Islam Al-Kulayni’ Who died in the year 329 H"
        ]
    }
    kafi.chapters = []

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-1\\"), "Volume One",
                     "الجزء الأول‏", "First volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-2\\"), "Volume Two",
                     "الجزء الثاني‏", "Second volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-3\\"),
                     "Volume Three", "الجزء الثالث‏",
                     "Third volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-4\\"),
                     "Volume Four", "الجزء الرابع‏",
                     "Forth volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-5\\"),
                     "Volume Five", "الجزء الخامس‏",
                     "Fifth volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-6\\"), "Volume Six",
                     "الجزء السادس‏", "Sixth volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-7\\"),
                     "Volume Seven", "الجزء السابع‏",
                     "Seventh volume of Al-Kafi"))

    kafi.chapters.append(
        build_volume(get_path("hubeali_com\\Al-Kafi-Volume-8\\"),
                     "Volume Eight", "الجزء الثامن‏",
                     "Eighth volume of Al-Kafi", True))

    kafi.verse_start_index = 0
    kafi.index = BOOK_INDEX
    kafi.path = BOOK_PATH

    crumb = Crumb()
    crumb.titles = kafi.titles
    crumb.indexed_titles = kafi.titles
    crumb.path = kafi.path
    kafi.crumbs = [crumb]

    set_index(kafi, [0, 0, 0, 0], 0)

    return kafi
def get_adjusted_chapter(volume: Chapter, book: Chapter, cfile, chapter_index):
    hadith_index = 0
    # book of hajj is split into another book on ziyarat https://thaqalayn.netlify.app/#/books/al-kafi:4:4?lang=en but this is not the case in https://thaqalayn.net/book/4
    if volume.local_index == 4:
        if book.local_index == 3:
            if chapter_index == 0:
                # Chapter 228 is merged into the end of chapter 227 in hubeali
                book.chapters.insert(
                    227,
                    create_chapter(
                        "دُعَاءٌ آخَرُ عِنْدَ قَبْرِ أَمِيرِ الْمُؤْمِنِينَ ع‏"
                    ))
                book.chapters[227].verses.append(
                    book.chapters[226].verses.pop(1))

    # vol 5 book 2 has missing chapter 82
    if volume.local_index == 5:
        if book.local_index == 2:
            # reserve missing chapter from beginning since we parse chapter file 159 before 82 and cause index out of bound
            if chapter_index == 0:
                # Chapter 82 missing in hubeali
                book.chapters.insert(81, {})
            if chapter_index == 81:
                book.chapters[chapter_index] = load_chapter_from_file(
                    "raw\\corrections\\al-kafi_v5_b2_c82.json")
        if book.local_index == 3:
            # TODO: hadith 3 in chapter 120 missing, based on noor
            # TODO: one hadith in chapter 124 missing, based on noor
            # Chapters on slaves missing Sarwar translations: from https://thaqalayn.net/chapter/5/3/112 to https://thaqalayn.net/chapter/5/3/137
            if chapter_index == 0:
                # Missing chapters
                book.chapters.insert(
                    22, create_chapter("بَابُ تَزْوِيجِ أُمِّ كُلْثُوم‏"))
                book.chapters.insert(
                    121,
                    create_chapter(
                        "بَابُ الرَّجُلِ يُزَوِّجُ عَبْدَهُ أَمَتَهُ ثُمَّ يَشْتَهِيهَا"
                    ))
                book.chapters.insert(132, create_chapter("بَاب‏"))
                book.chapters.insert(
                    177,
                    create_chapter(
                        "بَابُ أَنَّهُ لَا غَيْرَةَ فِي الْحَلَال‏"))
                book.chapters.insert(
                    190,
                    create_chapter(
                        "بَابُ تَفْسِيرِ مَا يَحِلُّ مِنَ النِّكَاحِ وَ مَا يَحْرُمُ وَ الْفَرْقِ بَيْنَ النِّكَاحِ وَ السِّفَاحِ وَ الزِّنَى وَ هُوَ مِنْ كَلَامِ يُونُس‏"
                    ))
            # Hadith 2 and 3 missing in chapter 22 of hubeali
            if chapter_index == 21:
                book.chapters[chapter_index] = load_chapter_from_file(
                    "raw\\corrections\\al-kafi_v5_b3_c22.json")
            # Hadith 4-9 missing in chapter 190 of hubeali
            if chapter_index == 189:
                book.chapters[chapter_index] = load_chapter_from_file(
                    "raw\\corrections\\al-kafi_v5_b3_c190.json")

    if volume.local_index == 6:
        if book.local_index == 2:
            if chapter_index == 0:
                book.chapters.insert(
                    28,
                    create_chapter(
                        "بَابُ الْفَرْقِ بَيْنَ مَنْ طَلَّقَ عَلَى غَيْرِ السُّنَّةِ وَ بَيْنَ الْمُطَلَّقَةِ إِذَا خَرَجَتْ وَ هِيَ فِي عِدَّتِهَا أَوْ أَخْرَجَهَا زَوْجُهَا"
                    ))
        # thaqalayn.net is missing a whole book on slavery: https://thaqalayn.netlify.app/#/books/al-kafi:6:3
        # so we skip adding translation to this book, note: book.local_index is 1 based
        if book.local_index >= 3:
            book = volume.chapters[book.local_index]
        if book.local_index == 6:
            # reserve missing chapter from beginning since we parse chapter file 159 before 82 and cause index out of bound
            if chapter_index == 0:
                book.chapters.insert(
                    86, create_chapter("بَابُ أَلْبَانِ الْإِبِل‏"))
            if chapter_index == 133:
                book.chapters[chapter_index] = load_chapter_from_file(
                    "raw\\corrections\\al-kafi_v6_b6_c134.json")

    if volume.local_index == 7:
        if book.local_index == 2:
            if chapter_index == 0:
                book.chapters.insert(
                    9,
                    create_chapter(
                        "بَابُ الْعِلَّةِ فِي أَنَّ السِّهَامَ لَا تَكُونُ أَكْثَرَ مِنْ سِتَّةٍ وَ هُوَ مِنْ كَلَامِ يُونُس‏"
                    ))
            if chapter_index >= 1:
                chapter_index += 1

    if volume.local_index == 8 and chapter_index > 0:
        # There is only one book and each hadith is in its own chapter in thaqalayn.net
        cumsum_index = next(i for i, v in enumerate(V8_HADITH_CUMSUM)
                            if v >= chapter_index + 1)
        cumsum = V8_HADITH_CUMSUM[cumsum_index - 1]
        hadith_index = chapter_index - cumsum
        chapter_index = cumsum_index

    return (book.chapters[chapter_index], hadith_index)
Esempio n. 19
0
def build_alhassanain_baabs(file) -> List[Chapter]:
    baabs: List[Chapter] = []
    logger.info("Adding Al-Kafi file %s", file)

    translation = Translation()
    translation.name = "HubeAli.com"
    translation.lang = Language.EN.value
    translation.id = HUBEALI_TRANSLATION_ID

    with open(file, 'r', encoding='utf8') as qfile:
        inner_html = qfile.read()
        sections = inner_html.split("<br clear=all>")
        for section in sections:
            section_soup = BeautifulSoup(section, 'html.parser')

            headings = section_soup.select(".Heading1Center")
            if not headings:
                continue

            # process "the book of" chapter
            baab_titles = extract_headings(headings)

            en_title = baab_titles[Language.EN.value]

            baab = None
            for existing_baab in baabs:
                if existing_baab.titles[Language.EN.value] == en_title:
                    baab = existing_baab

            if not baab:
                baab = Chapter()
                baab.part_type = PartType.Book
                baab.titles = baab_titles
                baab.chapters = []

                baabs.append(baab)

            # process chapters
            chapters = section_soup.select(".Heading2Center")
            chapters_len = len(chapters)
            for subchapter_index in range(math.ceil(chapters_len / 2)):
                subchapter_heading_index = subchapter_index * 2

                remaining_chapters = chapters[subchapter_heading_index:]
                if len(remaining_chapters) > 1:
                    remaining_chapters = remaining_chapters[:2]
                chapter_titles = extract_headings(remaining_chapters)

                chapter = Chapter()
                chapter.part_type = PartType.Chapter
                chapter.titles = chapter_titles
                chapter.verse_translations = [translation]
                chapter.verses = []

                baab.chapters.append(chapter)

                last_element = remaining_chapters[-1]
                last_element = last_element.next_sibling

                verse: Verse = None
                while (last_element is not None and
                       (isinstance(last_element, NavigableString) or
                        (is_tag(last_element)
                         and 'Heading2Center' not in last_element['class']))):
                    is_a_tag = is_tag(last_element)
                    if is_a_tag and 'libAr' in last_element['class']:

                        # push the last verse if its not the start of chapter
                        if verse != None:
                            chapter.verses.append(verse)

                        verse = Verse()
                        verse.part_type = PartType.Hadith
                        verse.translations = {}
                        verse.translations[HUBEALI_TRANSLATION_ID] = []

                        verse.text = [last_element.get_text(strip=True)]

                    if is_a_tag and 'libNormal' in last_element['class']:
                        verse.translations[HUBEALI_TRANSLATION_ID].append(
                            last_element.get_text(strip=True))

                    last_element = last_element.next_sibling

                if verse != None:
                    chapter.verses.append(verse)

    return baabs
Esempio n. 20
0
def build_hubeali_book_8(dirname) -> List[Chapter]:
    logger.info("Adding Al-Kafi dir %s", dirname)

    cfiles = glob.glob(dirname + "c*.xhtml")

    book = Chapter()
    book.part_type = PartType.Book
    book.titles = {}
    # Arabic title comes from previous file
    book.titles[
        Language.AR.
        value] = "&#1603;&#1578;&#1575;&#1576; &#1575;&#1604;&#1585;&#1617;&#1614;&#1608;&#1618;&#1590;&#1614;&#1577;&#1616;"
    book.titles[Language.EN.value] = "The Book - Garden (of Flowers)"
    book.chapters = []

    is_the_end = False
    previous_hadith_num = 14449
    chapter = None
    chapter_title_ar = None
    hadith_ar = []
    hadith_en = []
    for cfile in cfiles:
        if is_the_end:
            break

        logger.info("Processing file %s", cfile)

        with open(cfile, 'r', encoding='utf8') as qfile:
            file_html = qfile.read()
            file_html = file_correction(cfile, file_html)
            soup = BeautifulSoup(file_html, 'html.parser')

            heading = soup.body.h1
            if we_dont_care(heading):
                continue

            if table_of_contents(heading):
                hadith_ar.append(get_contents(soup.body.contents[-2]))
                continue

            heading_en = get_contents(heading.a)
            is_hadith_title = V8_HADITH_TITLE_PATTERN.match(heading_en)
            # sometimes the anchor is early terminated
            if not heading_en or is_hadith_title:
                heading_en = get_contents(heading)

            if chapter_title_ar or not chapter:
                chapter = Chapter()
                chapter.part_type = PartType.Chapter
                chapter.titles = {}
                if chapter_title_ar:
                    chapter.titles[Language.AR.value] = chapter_title_ar
                else:
                    chapter.titles[
                        Language.AR.
                        value] = "&#1576;&#1616;&#1587;&#1618;&#1605;&#1616; &#1575;&#1604;&#1604;&#1617;&#1614;&#1607;&#1616; &#1575;&#1604;&#1585;&#1617;&#1614;&#1581;&#1618;&#1605;&#1614;&#1606;&#1616; &#1575;&#1604;&#1585;&#1617;&#1614;&#1581;&#1616;&#1610;&#1605;&#1616;"
                if heading_en:
                    chapter.titles[Language.EN.value] = heading_en
                else:
                    chapter.titles[
                        Language.EN.
                        value] = "In the name of Allah, the Beneficent, the Merciful"
                chapter_title_ar = None
                chapter.verses = []
                chapter.verse_translations = [hubbeali_translation]

                book.chapters.append(chapter)
            elif is_hadith_title:
                hadith_en.append(heading_en)

            last_element = soup.find('p', 'first-in-chapter')

            while last_element:
                if is_newline(last_element):
                    last_element = last_element.next_sibling
                    continue

                is_a_tag = is_tag(last_element)
                is_paragraph = is_a_tag and last_element.name == 'p'
                is_not_section_break_paragraph = is_paragraph and not is_section_break_tag(
                    last_element)
                is_arabic = is_rtl_tag(last_element)

                element_content = get_contents(last_element)
                element_content = element_content.replace(
                    'style="font-style: italic; font-weight: bold"',
                    'class="ibTxt"')
                element_content = element_content.replace(
                    'style="font-weight: bold"', 'class="bTxt"')
                element_content = element_content.replace(
                    'style="font-style: italic"', 'class="iTxt"')

                is_new_hadith = V8_HADITH_BEGINNING_PATTERN.match(
                    last_element.get_text(strip=True))
                is_the_end = element_content.startswith(
                    "&#1578;&#1614;&#1605;&#1617;&#1614; &#1603;&#1616;&#1578;&#1614;&#1575;&#1576;&#1615; &#1575;&#1604;&#1585;&#1617;&#1614;&#1608;&#1618;&#1590;&#1614;&#1577;&#1616; &#1605;&#1616;&#1606;&#1614;"
                )

                # We commit the hadith that has been building up until now if we encounter a new hadith beginning
                if (is_new_hadith or is_the_end) and hadith_ar and hadith_en:
                    add_hadith(chapter, hadith_ar, hadith_en)
                    hadith_ar = []
                    hadith_en = []

                if is_new_hadith:
                    hadith_num = int(is_new_hadith.group(1))
                    if previous_hadith_num + 1 != hadith_num:
                        print("Skipped one hadith " +
                              str(previous_hadith_num) + " to " +
                              str(hadith_num) + " title: " + element_content)
                    previous_hadith_num = hadith_num

                if is_chapter_title(last_element):
                    if hadith_ar and hadith_en:
                        add_hadith(chapter, hadith_ar, hadith_en)
                        hadith_ar = []
                        hadith_en = []

                    chapter_title_ar = element_content
                elif is_arabic:
                    hadith_ar.append(element_content)
                elif is_not_section_break_paragraph:
                    hadith_en.append(element_content)
                    if is_the_end:
                        add_hadith(chapter, hadith_ar, hadith_en,
                                   PartType.Heading)

                last_element = last_element.next_sibling

    return [book]
Esempio n. 21
0
def build_hubeali_books(dirname) -> List[Chapter]:
    books: List[Chapter] = []
    logger.info("Adding Al-Kafi dir %s", dirname)

    cfiles = glob.glob(dirname + "c*.xhtml")

    book = None
    chapter = None
    book_title_ar = None
    chapter_title_ar = None
    hadith_ar = []
    hadith_en = []
    for cfile in cfiles:
        logger.info("Processing file %s", cfile)

        with open(cfile, 'r', encoding='utf8') as qfile:
            file_html = qfile.read()
            file_html = file_correction(cfile, file_html)
            soup = BeautifulSoup(file_html, 'html.parser')

            heading = soup.body.h1
            if we_dont_care(heading):
                continue

            if table_of_contents(heading):
                book_title_ar = get_contents(soup.body.contents[-2])
                continue

            heading_en = get_contents(heading.a)
            # sometimes the anchor is early terminated
            if not heading_en:
                heading_en = get_contents(heading)

            if book_title_ar:
                book = Chapter()
                book.part_type = PartType.Book
                book.titles = {}
                # Arabic title comes from previous file
                book.titles[Language.AR.value] = book_title_ar
                book.titles[Language.EN.value] = heading_en
                book_title_ar = None
                book.chapters = []

                books.append(book)

            elif (chapter_title_ar
                  or not chapter) and heading_en.startswith('Chapter'):
                chapter = Chapter()
                chapter.part_type = PartType.Chapter
                chapter.titles = {}
                chapter.titles[Language.AR.value] = chapter_title_ar
                chapter.titles[Language.EN.value] = heading_en
                chapter_title_ar = None
                chapter.verse_translations = [hubbeali_translation]
                chapter.verses = []

                book.chapters.append(chapter)

            elif chapter_title_ar:
                add_hadith(chapter, [chapter_title_ar], [heading_en],
                           PartType.Heading)

                chapter_title_ar = None

            last_element = soup.find('p', 'first-in-chapter')

            while last_element:
                if is_newline(last_element):
                    last_element = last_element.next_sibling
                    continue

                is_a_tag = is_tag(last_element)
                is_paragraph = is_a_tag and last_element.name == 'p'
                is_not_section_break_paragraph = is_paragraph and not is_section_break_tag(
                    last_element)
                is_arabic = is_rtl_tag(last_element)

                element_content = get_contents(last_element)
                element_content = element_content.replace(
                    'style="font-style: italic; font-weight: bold"',
                    'class="ibTxt"')
                element_content = element_content.replace(
                    'style="font-weight: bold"', 'class="bTxt"')
                element_content = element_content.replace(
                    'style="font-style: italic"', 'class="iTxt"')

                is_end_of_hadith = END_OF_HADITH_PATTERN.search(
                    element_content)

                if is_book_title(last_element):
                    if hadith_ar and hadith_en:
                        add_hadith(chapter, hadith_ar, hadith_en,
                                   PartType.Heading)
                        hadith_ar = []
                        hadith_en = []

                    # hubeali put chapters on ziyarat as separate book but we're going to stay true to the indexing on
                    # other copies out there and have the chapters under this as part of book of Hajj
                    if not cfile.endswith('Al-Kafi-Volume-4\\c346.xhtml'):
                        book_title_ar = element_content
                        chapter = None
                elif is_chapter_title(last_element):
                    if hadith_ar and hadith_en:
                        if chapter:
                            add_hadith(chapter, hadith_ar, hadith_en)
                        else:
                            book.descriptions = {}
                            book.descriptions[Language.AR.value] = hadith_ar
                            book.descriptions[Language.EN.value] = hadith_en
                        hadith_ar = []
                        hadith_en = []

                    chapter_title_ar = element_content
                elif is_arabic:
                    hadith_ar.append(element_content)
                # elif is_book_ending(last_element):
                # 	add_hadith(chapter, hadith_ar, [element_content], PartType.Heading)
                # 	hadith_ar = []
                # 	hadith_en = []
                elif is_not_section_break_paragraph:
                    hadith_en.append(element_content)

                if is_end_of_hadith:
                    add_hadith(chapter, hadith_ar, hadith_en)
                    hadith_ar = []
                    hadith_en = []

                last_element = last_element.next_sibling

    return books
Esempio n. 22
0
 def test_chapter_single_create(self):
     chapter = Chapter(dictionary=self.dictionary, chapter_name='food')
     self.refresh_db(chapter)
     yield db
     assert db.session.query(Chapter).count() == 1
def add_chapter_content(chapter: Chapter, filepath, hadith_index=0):
    if filepath.endswith('\\0.html'):
        error_msg = f"Skipping zero file {filepath}"
        logger.warn(error_msg)
        SEQUENCE_ERRORS.append(error_msg)
        return

    verses = chapter.verses
    heading_count = len([x for x in verses if x.part_type == PartType.Heading])

    sarwar_exists = next((item for item in chapter.verse_translations
                          if item.id == SARWAR_TRANSLATION_ID), None)
    if not sarwar_exists:
        chapter.verse_translations.append(sarwar_translation)

    with open(filepath, 'r', encoding='utf8') as qfile:
        file_html = qfile.read()

        if not 'en' in chapter.titles:
            file_soup = BeautifulSoup(file_html, 'html.parser')

            card_body = file_soup.find('div', 'card-body')
            chapter_title = get_contents(card_body.find('h3'))
            chapter.titles['en'] = chapter_title

        ##### Processing each hadith separately

        hadith_htmls = re.split('<hr/?>', file_html)

        for hadith_html in hadith_htmls:
            if we_dont_care(hadith_html):
                continue

            soup = BeautifulSoup(hadith_html, 'html.parser')

            all_paras = soup.find_all('p')

            para_index = 0
            hadith_ar = []
            while is_rtl_tag(all_paras[para_index]):
                hadith_ar.append(get_contents(all_paras[para_index]))
                para_index += 1

            hadith_en = get_contents(all_paras[para_index])
            para_index += 1

            if hadith_index >= len(verses) - heading_count:
                # hubeali rightly splits first chapter in book of inheritance into two
                # but thaqalayn.net has it as one chapter, so we'll skip adding ahadith
                if chapter.path == '/books/al-kafi:7:2:1':
                    break

                verse = Verse()
                verse.text = hadith_ar
                verse.part_type = PartType.Hadith.value
                verse.translations = {}

                verses.append(verse)

                site_path = sitepath_from_filepath(filepath)
                if chapter.crumbs:
                    my_site_path = chapter.crumbs[-1].path
                else:
                    my_site_path = site_path.replace('/', ':')
                error_msg = f"Appending new hadith from Sarwar to hubeali, hadith #{hadith_index+1} from https://thaqalayn.net/chapter/{site_path} to https://thaqalayn.netlify.app/#{my_site_path}"
                logger.warn(error_msg)
                SEQUENCE_ERRORS.append(error_msg)
            else:
                # TODO: create new verse if the verse at this index doesn't match the one being inserted
                # perhaps use https://github.com/ztane/python-Levenshtein or https://pypi.org/project/jellyfish/
                verse = verses[hadith_index]

                if verse.part_type == PartType.Heading:
                    hadith_index += 1
                    verse = verses[hadith_index]

                if verse.part_type != PartType.Hadith:
                    error_msg = f"Hadith index {hadith_index} is of part_type {verse.part_type} in https://thaqalayn.netlify.app/#{chapter.crumbs[-1].path}"
                    logger.warn(error_msg)
                    SEQUENCE_ERRORS.append(error_msg)

            verse.translations[SARWAR_TRANSLATION_ID] = [hadith_en]

            if len(all_paras) > para_index + 1:
                grading_title = get_contents(all_paras[para_index])
                para_index += 1
                if grading_title.startswith('Grading:'):
                    grading = []
                    # if len(all_paras[3:-3]) != 2 and len(all_paras[3:-3]) != 1:
                    # 	raise Exception("We are in " + filepath + " and all_paras is " + str(all_paras))
                    for grading_para in all_paras[para_index:-3]:
                        grading.append(get_contents(grading_para))
                    verse.gradings = grading

            hadith_index += 1

    # Volume 8 of al-kafi is one file per hadith on thaqalayn.net and it'll warn on every page
    # since there is always more ahadith on hubeali's chapter
    if hadith_index != len(
            verses) - heading_count and 'al-kafi:8:1' not in chapter.path:
        site_path = sitepath_from_filepath(filepath)
        error_msg = f"Sarwar has {hadith_index} hadith but hubeali has {len(verses)} hadith: https://thaqalayn.net/chapter/{site_path} vs https://thaqalayn.netlify.app/#{chapter.crumbs[-1].path}"
        logger.warn(error_msg)
        SEQUENCE_ERRORS.append(error_msg)
Esempio n. 24
0
 def test_chapter_multiple_create(self):
     chapter_1 = Chapter(dictionary=self.dictionary, chapter_name='food')
     chapter_2 = Chapter(dictionary=self.dictionary, chapter_name='hobby')
     self.refresh_db(chapter_1, chapter_2, self.dictionary)
     yield db
     assert db.session.query(Chapter) == 2
Esempio n. 25
0
def project(id, title):
	register_form = RegistrationForm()
	login_form = LoginForm()
	if login_form.login_submit.data:
		if login_form.validate_on_submit():
			loginuser = User.query.filter_by(email=login_form.login_email.data).first()
			if loginuser is None or not loginuser.check_password(login_form.login_password.data):
				flash('Invalid email or password')
				current_page = request.url
				if not current_page or url_parse(current_page).netloc != '':
					next_page = url_for('index')
				return redirect(current_page)
			login_user(loginuser, remember=login_form.remember_me.data)
			current_page = request.url
			if not current_page or url_parse(current_page).netloc != '':
				next_page = url_for('index')
			return redirect(current_page)
	elif register_form.register_submit.data:
		if register_form.validate_on_submit():
			register_user = User(username=register_form.register_username.data, email=register_form.register_email.data)
			register_user.set_password(register_form.register_password.data)
			db.session.add(register_user)
			db.session.commit()
			flash('Thank you for registering')
			current_page = request.url
			if not current_page or url_parse(current_page).netloc != '':
				next_page = url_for('index')
			return redirect(current_page)
	project = Project.query.filter_by(id=id).first()
	if project.cover_pic_credit:
		project.cover_pic_cred = markdown2.markdown(project.cover_pic_credit)
	chapters = Chapter.query.filter_by(project_id=project.id).order_by(Chapter.chapter_no.asc()).all()
	form = CreateChapterForm()
	if form.submit_chapter.data and form.validate_on_submit():
		chapter = Chapter(chapter_no=form.chapter_number.data, chapter_title=form.chapter_title.data, project_id=project.id, author_id=current_user.id)
		db.session.add(chapter)
		db.session.commit()
		return redirect(url_for('project', id=project.id, title=project.title))
	for c in chapters:
		if c.chapter_body is not None:
			if c.date_submitted < datetime(2018, 12, 31):
				c.body = markdown2.markdown(c.chapter_body)
			else:
				c.body = c.chapter_body
	form1 = CommentReviewForm()
	if form1.post_for_advice.data and form1.validate_on_submit():
		project.date_seek_review = datetime.utcnow()
		db.session.commit()
		return redirect(url_for('project', id=project.id, title=project.title))
	form2 = PublishForm()
	if form2.publish_project.data and form2.validate_on_submit():
		project.date_published = datetime.utcnow()
		db.session.commit()
		return redirect(url_for('project', id=project.id, title=project.title))
	form3 = ReviewForm()
	if form3.submit_review.data and form3.validate_on_submit():
		ratings = Rating(review=form3.review.data, score=form3.score.data, project_id=project.id, user_id=current_user.id)
		db.session.add(ratings)
		db.session.commit()
		return redirect(url_for('project', id=project.id, title=project.title))
	genre = []
	for p in project.genre:
		genre.append(p.name)
	keywords = (', '.join(genre))
	return render_template('project.html', title=project.title, keywords=keywords, description=project.synopsis, project=project, form=form, form1=form1, form2=form2, form3=form3, chapters=chapters, register_form=register_form, login_form=login_form)
def dashboard_manage_course():
    teacher = Teacher.query.filter_by(
        teacher_full_name=current_user.teacher_full_name).first()

    # Manage Course Overview
    course_overview_form = WebDevelopmentOverviewForm()
    if course_overview_form.validate_on_submit():
        course_overview = WebDevelopmentOverview(
            title=course_overview_form.title.data,
            overview=course_overview_form.body.data,
            youtube_link=course_overview_form.youtube_link.data,
        )
        db.session.add(course_overview)
        db.session.commit()
        flash('Your course overview has been posted!', 'success')
        return redirect(url_for('teacher.review_course_overview'))

    # Manage Course Table of Contents
    table_of_contents_form = TableOfContentsForm()
    if table_of_contents_form.validate_on_submit():
        table_of_contents = TableOfContents(
            title=table_of_contents_form.title.data,
            chapter=table_of_contents_form.chapter.data,
            link=table_of_contents_form.link.data,
        )
        db.session.add(table_of_contents)
        db.session.commit()
        flash('Your table of contents has been updated!', 'success')
        return redirect(url_for('teacher.review_table_of_contents'))

    # Chapters
    chapter_form = ChapterForm()
    if chapter_form.validate_on_submit():
        chapter = Chapter(
            course=chapter_form.course.data,
            chapter=chapter_form.chapter.data,
            chapter_link=chapter_form.chapter_link.data,
            comment_moderation_link=chapter_form.comment_moderation_link.data,
            chapter_quiz_1_link=chapter_form.chapter_quiz_1_link.data,
            overview=chapter_form.overview.data,
            accomplish=chapter_form.accomplish.data,
            youtube_link=chapter_form.youtube_link.data,
            conclusion=chapter_form.conclusion.data,
            objective_1=chapter_form.objective_1.data,
            objective_2=chapter_form.objective_2.data,
            objective_3=chapter_form.objective_3.data,
            objective_4=chapter_form.objective_4.data,
            objective_5=chapter_form.objective_5.data,
        )
        db.session.add(chapter)
        db.session.commit()
        flash(f'{chapter} has been added!', 'success')
        return redirect(url_for('teacher.review_chapters'))

    # Chapter Quiz
    chapter_quiz_form = ChapterQuizForm()
    if chapter_quiz_form.validate_on_submit():
        chapter_quiz = ChapterQuiz(
            course=chapter_quiz_form.course.data,
            chapter=chapter_quiz_form.chapter.data,
            quiz_1=chapter_quiz_form.quiz_1.data,
            quiz_2=chapter_quiz_form.quiz_2.data,
            quiz_3=chapter_quiz_form.quiz_3.data,
            quiz_4=chapter_quiz_form.quiz_4.data,
            quiz_5=chapter_quiz_form.quiz_5.data
        )
        db.session.add(chapter_quiz)
        db.session.commit()
        flash('Chapter quiz has been added!', 'success')
        return redirect(url_for('teacher.review_chapter_quiz'))

    # General mulitple choices quiz
    mulitple_choice_quiz_form = GeneralOwnChoiceQuizForm()
    if mulitple_choice_quiz_form.validate_on_submit():
        chapter_quiz = GeneralMultipleChoicesQuiz(
            course=mulitple_choice_quiz_form.course.data,
            quiz_1=mulitple_choice_quiz_form.quiz_1.data,
            quiz_2=mulitple_choice_quiz_form.quiz_2.data,
            quiz_3=mulitple_choice_quiz_form.quiz_3.data,
            quiz_4=mulitple_choice_quiz_form.quiz_4.data,
            quiz_5=mulitple_choice_quiz_form.quiz_5.data,
            quiz_6=mulitple_choice_quiz_form.quiz_6.data,
            quiz_7=mulitple_choice_quiz_form.quiz_7.data,
            quiz_8=mulitple_choice_quiz_form.quiz_8.data,
            quiz_9=mulitple_choice_quiz_form.quiz_9.data,
            quiz_10=mulitple_choice_quiz_form.quiz_10.data
        )
        db.session.add(chapter_quiz)
        db.session.commit()
        flash('Chapter quiz has been added!', 'success')
        return redirect(url_for(
            'teacher.review_general_mulitiple_choices_quiz'))

    all_quizzes = ChapterQuiz.query.filter_by(
        course=teacher.teacher_course).all()
    all_multiple_quizzes = GeneralMultipleChoicesQuiz.query.filter_by(
        course=teacher.teacher_course).all()
    course_chapters = Chapter.query.filter_by(
        course=teacher.teacher_course).all()

    # Length
    all_chapters = len(Chapter.query.all())
    all_toc = len(TableOfContents.query.all())
    all_course_overview = len(WebDevelopmentOverview.query.all())
    all_chapter_quizzes = len(ChapterQuiz.query.all())
    all_general_multiple_choice_quizzes = len(
        GeneralMultipleChoicesQuiz.query.all())
    return render_template(
        'teacher/manage_course.html',
        title='Manage Your Course',
        teacher=teacher,

        # Course Overview
        course_overview_form=course_overview_form,
        all_course_overview=all_course_overview,

        # Table of Contents
        table_of_contents_form=table_of_contents_form,
        all_toc=all_toc,

        # Chapters
        chapter_form=chapter_form,
        course_chapters=course_chapters,
        all_chapters=all_chapters,

        # Chapter Quiz
        chapter_quiz_form=chapter_quiz_form,
        all_quizzes=all_quizzes,
        all_chapter_quizzes=all_chapter_quizzes,

        # Multiple Choice Quiz
        mulitple_choice_quiz_form=mulitple_choice_quiz_form,
        all_multiple_quizzes=all_multiple_quizzes,
        all_general_multiple_choice_quizzes=all_general_multiple_choice_quizzes
        )
def newChapter():
    if request.method == 'POST':
        dt = datetime.strptime(request.form['release_date'], '%Y-%m-%d')
        #ADDING CHAPTER
        chapter = Chapter(
            title = request.form['title'],
            manga_id = request.form['manga'],
            number = request.form['number'],
            release_date = dt,
        )

        
        db.session.add(chapter)

        db.session.flush() #cheat to get the Id after insert, 
        chapterId = chapter.id

        db.session.commit()
        #ADDING CHAPTER

        #ADDING PAGES TO CHAPTER
        count = 0
        uploaded_files = request.files.getlist("page[]")
        manga = Manga.query.filter_by(id=request.form['manga']).first()        

        for file in uploaded_files:
            count += 1
            
            filename = file.filename     
            
            #Each manga needs a folder, then each chapter needs one, then we insert the pages in
            mangaTitle = manga.title.replace(" ", "-")

            target = os.path.join(app.config['UPLOAD_FOLDER'], 'mangas')        

            target = os.path.join(target, mangaTitle)     

            if not os.path.isdir(target):
                os.mkdir(target)   

            target = os.path.join(target, 'chapter-' + request.form['number'])   

            if not os.path.isdir(target):
                os.mkdir(target)       

            title = 'page'+str(count)
            ext = os.path.splitext(filename)[1]
            destination = "/".join([target, title+ext])
            file.save(destination)

            page = Page(
                chapter_id = chapterId,
                page_number = count,
                image = 'mangas/' + mangaTitle + '/chapter-' + request.form['number'] + "/" + title + ext
            )

            db.session.add(page)
            db.session.commit()            
       

        flash('Chapter Registered!')
        return redirect(url_for('manga.read', id=manga.id))        

        #ADDING PAGES TO CHAPTER

    return render_template('/manga/chapter/new.html')
Esempio n. 28
0
def build_quran() -> Chapter:
    verses = build_verses(get_path("tanzil_net/quran_simple.txt"))
    verse_translations = []

    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.ansarian.txt"), "ansarian", "fa",
        "Hussain Ansarian",
        "https://fa.wikipedia.org/wiki/%D8%AD%D8%B3%DB%8C%D9%86_%D8%A7%D9%86%D8%B5%D8%A7%D8%B1%DB%8C%D8%A7%D9%86"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.ayati.txt"), "ayati", "fa",
        "AbdolMohammad Ayati",
        "https://fa.wikipedia.org/wiki/%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%85%D8%AD%D9%85%D8%AF_%D8%A2%DB%8C%D8%AA%DB%8C"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.bahrampour.txt"), "bahrampour",
        "fa", "Abolfazl Bahrampour",
        "https://fa.wikipedia.org/wiki/%D8%A7%D8%A8%D9%88%D8%A7%D9%84%D9%81%D8%B6%D9%84_%D8%A8%D9%87%D8%B1%D8%A7%D9%85%E2%80%8C%D9%BE%D9%88%D8%B1"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.fooladvand.txt"), "fooladvand",
        "fa", "Mohammad Mahdi Fooladvand",
        "https://fa.wikipedia.org/wiki/%D9%85%D8%AD%D9%85%D8%AF%D9%85%D9%87%D8%AF%DB%8C_%D9%81%D9%88%D9%84%D8%A7%D8%AF%D9%88%D9%86%D8%AF"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.ghomshei.txt"), "ghomshei", "fa",
        "Mahdi Elahi Ghomshei",
        "https://fa.wikipedia.org/wiki/%D9%85%D9%87%D8%AF%DB%8C_%D8%A7%D9%84%D9%87%DB%8C_%D9%82%D9%85%D8%B4%D9%87%E2%80%8C%D8%A7%DB%8C"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.khorramdel.txt"), "khorramdel",
        "fa", "Mostafa Khorramdel",
        "https://rasekhoon.net/mashahir/Show-904328.aspx")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.khorramshahi.txt"),
        "khorramshahi", "fa", "Baha'oddin Khorramshahi",
        "https://fa.wikipedia.org/wiki/%D8%A8%D9%87%D8%A7%D8%A1%D8%A7%D9%84%D8%AF%DB%8C%D9%86_%D8%AE%D8%B1%D9%85%D8%B4%D8%A7%D9%87%DB%8C"
    )
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.makarem.txt"), "makarem", "fa",
        "Naser Makarem Shirazi",
        "https://en.wikipedia.org/wiki/Naser_Makarem_Shirazi")
    insert_quran_translation(verses, verse_translations,
                             get_path("tanzil_net/translations/fa.moezzi.txt"),
                             "moezzi", "fa", "Mohammad Kazem Moezzi", "")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.mojtabavi.txt"), "mojtabavi",
        "fa", "Sayyed Jalaloddin Mojtabavi",
        "http://rasekhoon.net/mashahir/Show-118481.aspx")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/fa.sadeqi.txt"), "sadeqi", "fa",
        "Mohammad Sadeqi Tehrani",
        "https://fa.wikipedia.org/wiki/%D9%85%D8%AD%D9%85%D8%AF_%D8%B5%D8%A7%D8%AF%D9%82%DB%8C_%D8%AA%D9%87%D8%B1%D8%A7%D9%86%DB%8C"
    )

    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.ahmedali.txt"), "ahmedali", "en",
        "Ahmed Ali", "https://en.wikipedia.org/wiki/Ahmed_Ali_(writer)")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.ahmedraza.txt"), "ahmedraza",
        "en", "Ahmed Raza Khan",
        "https://en.wikipedia.org/wiki/Ahmed_Raza_Khan_Barelvi")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.arberry.txt"), "arberry", "en",
        "A. J. Arberry", "https://en.wikipedia.org/wiki/Arthur_John_Arberry")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.daryabadi.txt"), "daryabadi",
        "en", "Abdul Majid Daryabadi",
        "https://en.wikipedia.org/wiki/Abdul_Majid_Daryabadi")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.hilali.txt"), "hilali", "en",
        "Muhammad Taqi-ud-Din al-Hilali and Muhammad Muhsin Khan",
        "https://en.wikipedia.org/wiki/Noble_Quran_(Hilali-Khan)")
    insert_quran_translation(verses, verse_translations,
                             get_path("tanzil_net/translations/en.itani.txt"),
                             "itani", "en", "Talal Itani", "")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.maududi.txt"), "maududi", "en",
        "Abul Ala Maududi",
        "https://en.wikipedia.org/wiki/Abul_A%27la_Maududi")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.mubarakpuri.txt"), "mubarakpuri",
        "en", "Safi-ur-Rahman al-Mubarakpuri",
        "https://en.wikipedia.org/wiki/Safiur_Rahman_Mubarakpuri")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.pickthall.txt"), "pickthall",
        "en", "Mohammed Marmaduke William Pickthall",
        "https://en.wikipedia.org/wiki/Marmaduke_Pickthall")
    insert_quran_translation(verses, verse_translations,
                             get_path("tanzil_net/translations/en.qarai.txt"),
                             "qarai", "en", "Ali Quli Qarai", "")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.qaribullah.txt"), "qaribullah",
        "en", "Hasan al-Fatih Qaribullah and Ahmad Darwish", "")
    insert_quran_translation(verses, verse_translations,
                             get_path("tanzil_net/translations/en.sahih.txt"),
                             "sahih", "en", "Saheeh International",
                             "http://www.saheehinternational.com/")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.sarwar.txt"), "sarwar", "en",
        "Muhammad Sarwar",
        "https://en.wikipedia.org/wiki/Shaykh_Muhammad_Sarwar")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.shakir.txt"), "shakir", "en",
        "Mohammad Habib Shakir",
        "https://en.wikipedia.org/wiki/Muhammad_Habib_Shakir")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.transliteration.txt"),
        "transliteration", "en", "English Transliteration", "")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.wahiduddin.txt"), "wahiduddin",
        "en", "Wahiduddin Khan",
        "https://en.wikipedia.org/wiki/Wahiduddin_Khan")
    insert_quran_translation(
        verses, verse_translations,
        get_path("tanzil_net/translations/en.yusufali.txt"), "yusufali", "en",
        "Abdullah Yusuf Ali",
        "https://en.wikipedia.org/wiki/Abdullah_Yusuf_Ali")

    chapters = build_chapters(get_path("tanzil_net/quran-data.xml"), verses,
                              verse_translations)

    q = Chapter()
    q.index = BOOK_INDEX
    q.path = BOOK_PATH
    q.verse_start_index = 0
    q.part_type = PartType.Book
    q.titles = {
        Language.EN.value: "The Holy Quran",
        Language.AR.value: "القرآن الكريم"
    }
    q.descriptions = {Language.EN.value: ["Was revealed to the prophet SAW"]}
    q.chapters = chapters
    q.verse_translations = verse_translations
    q.default_verse_translation_ids = {"en": "en.qarai", "fa": "fa.makarem"}

    crumb = Crumb()
    crumb.titles = q.titles
    crumb.indexed_titles = q.titles
    crumb.path = q.path
    q.crumbs = [crumb]

    set_index(q, [0, 0], 0)

    return q