from sefaria.model import *
from helper.link import add_links_from_text
from sefaria.system.database import db
from sefaria.utils.talmud import section_to_daf

# Find links that were generated from a Berakhot text
oids = db.texts.find({"title": "Berakhot"}).distinct("_id")
tanakh_links = LinkSet({"source_text_oid": {"$in": oids}})

tanakh_links.delete()

berakhot = Version().load({"title": "Berakhot", "versionTitle": "Wikisource Talmud Bavli"})

for i in range(len(berakhot.chapter)):
    ref = "Berakhot %s" % section_to_daf(i+1)
    print "Scanning %s" % ref
    add_links_from_text(ref, berakhot.language, berakhot.chapter[i], berakhot._id, 1)
Example #2
0
        continue
    if "Tanach" in index.categories:
        continue
    talmud = True if "Talmud" in index.categories else False

    for i in range(len(text['chapter'])):
        if talmud:
            if "Bavli" in index.categories and i < 2:
                continue
            chap = section_to_daf(i + 1)
        else:
            chap = i + 1
        ref = text['title'] + " " + str(chap)
        print ref
        try:
            result = add_links_from_text(ref, text['language'],
                                         text['chapter'][i], text['_id'], user)
            if result:
                text_total[text["title"]] += len(result)
        except Exception, e:
            print e

total = 0
for text in text_order:
    num = text_total[text]
    index = txt.get_index(text)
    if getattr(index, "categories", None):
        print text.replace(",", ";") + "," + str(num) + "," + ",".join(
            index.categories)
    else:
        print text.replace(",", ";") + "," + str(num)
    total += num