# encoding=utf-8 import os from os.path import dirname as loc from sources.Shulchan_Arukh.ShulchanArukh import * root_dir = loc(loc(loc(os.path.abspath(__file__)))) xml_loc = os.path.join(root_dir, 'Yoreh_Deah.xml') filenames = [ u"txt_files/Yoreh_Deah/part_1/שולחן ערוך יורה דעה חלק א ביאור הגרא.txt", u"txt_files/Yoreh_Deah/part_2/שולחן ערוך יורה דעה חלק ב ביאור הגר''א.txt", u"txt_files/Yoreh_Deah/part_3/ביאור הגרא שולחן ערוך יורה דעה חלק ג.txt", u"txt_files/Yoreh_Deah/part_4/שולחן ערוך יורה דעה חלק ד ביאור הגרא.txt" ] filenames = dict( zip(range(1, 5), [os.path.join(root_dir, f) for f in filenames])) root = Root(xml_loc) commentaries = root.get_commentaries() gra = commentaries.get_commentary_by_title(u"Beur HaGra") assert isinstance(gra, Commentary) for vol_num in range(1, 5): print 'vol {}'.format(vol_num) gra.remove_volume(vol_num) with codecs.open(filenames[vol_num], 'r', 'utf-8') as fp: volume = gra.add_volume(fp.read(), vol_num) assert isinstance(volume, Volume) volume.mark_simanim(u'@22([\u05d0-\u05ea]{1,3})')
import os from os.path import dirname as loc from sources.Shulchan_Arukh.ShulchanArukh import * commentary_list = [ ("Turei Zahav", u"טורי זהב"), ("Eshel Avraham", u"אשל אברהם"), ("Be'er HaGolah", u"באר הגולה"), ("Ateret Zekenim", u"עטרת זקנים"), ("Chok Yaakov", u"חק יעקב"), ("Sha'arei Teshuvah", u"שערי תשובה") ] commentary_list = [dict(zip(('en_title', 'he_title'), c)) for c in commentary_list] root_dir = loc(loc(loc(os.path.abspath(__file__)))) xml_loc = os.path.join(root_dir, 'Orach_Chaim.xml') if not os.path.exists(xml_loc): Root.create_skeleton(xml_loc) root = Root(xml_loc) base = root.get_base_text() base.add_titles("Shulchan Arukh, Orach Chayim", u"שולחן ערוך אורח חיים") xml_commentaries = root.get_commentaries() for commentary in commentary_list: c = xml_commentaries.get_commentary_by_title(commentary['en_title']) if c is None: xml_commentaries.add_commentary(**commentary) root.export()