Esempio n. 1
0
def update_table_of_contents():
    toc = []

    # Add an entry for every text we know about
    indices = sefaria.db.index.find()
    for i in indices:
        del i["_id"]
        if i["categories"][0] == "Commentary":
            # Special case commentary below
            continue
        if i["categories"][0] not in order:
            i["categories"].insert(0, "Other")
        node = get_or_make_summary_node(toc, i["categories"])
        text = add_counts_to_index(i)
        node.append(text)

    # Special handling to list available commentary texts which do not have
    # individual index records
    commentary_texts = sefaria.get_commentary_texts_list()
    for c in commentary_texts:
        i = sefaria.get_index(c)
        node = get_or_make_summary_node(toc, i["categories"])
        text = add_counts_to_index(i)
        node.append(text)

    # Annotate categories nodes with counts
    for cat in toc:
        add_counts_to_category(cat)

    # Recursively sort categories and texts
    toc = sort_toc_node(toc, recur=True)

    save_toc(toc)
    return toc
Esempio n. 2
0
def update_table_of_contents():
	toc = []

	# Add an entry for every text we know about
	indices = sefaria.db.index.find()
	for i in indices:
		del i["_id"]
		if i["categories"][0] == "Commentary":
			# Special case commentary below
			continue
		if i["categories"][0] not in order:
			i["categories"].insert(0, "Other")
		node = get_or_make_summary_node(toc, i["categories"])
		text = add_counts_to_index(i)
		node.append(text)

	# Special handling to list available commentary texts which do not have
	# individual index records
	commentary_texts = sefaria.get_commentary_texts_list()
	for c in commentary_texts:
		i = sefaria.get_index(c)
		node = get_or_make_summary_node(toc, i["categories"])
		text = add_counts_to_index(i)
		node.append(text)

	# Annotate categories nodes with counts
	for cat in toc:
		add_counts_to_category(cat)

	# Recursively sort categories and texts
	toc = sort_toc_node(toc, recur=True)

	save_toc(toc)
	return toc
Esempio n. 3
0
def update_table_of_contents():
	toc = []

	# Add an entry for every text we know about
	indices = db.index.find()
	for i in indices:
		del i["_id"]
		if i["categories"][0] == "Commentary":
			# Special case commentary below
			continue
		if i["categories"][0] not in order:
			i["categories"].insert(0, "Other")
		node = get_or_make_summary_node(toc, i["categories"])
		#the toc "contents" attr is returned above so for each text appends the counts and index info
		text = add_counts_to_index(i)
		node.append(text)

	# Special handling to list available commentary texts which do not have
	# individual index records
	commentary_texts = texts.get_commentary_texts_list()
	for c in commentary_texts:
		i = texts.get_index(c)
		#TODO: duplicate index records where one is a commentary and another is not labeled as one can make this crash.
		#this fix takes care of the crash.
		if len(i["categories"]) >= 1 and i["categories"][0] == "Commentary":
			cats = i["categories"][1:2] + ["Commentary"] + i["categories"][2:]
		else:
			cats = i["categories"][0:1] + ["Commentary"] + i["categories"][1:]
		node = get_or_make_summary_node(toc, cats)
		text = add_counts_to_index(i)
		node.append(text)

	# Annotate categories nodes with counts
	for cat in toc:
		add_counts_to_category(cat)

	# Recursively sort categories and texts
	toc = sort_toc_node(toc, recur=True)

	save_toc(toc)
	save_toc_to_db()

	return toc