示例#1
0
def generate_refs_list(query={}):
	"""
	Generate a list of refs to all available sections.
	"""
	refs = []
	counts = db.counts.find(query)
	for c in counts:
		if "title" not in c:
			continue # this is a category count

		i = texts.get_index(c["title"])
		if ("error" in i):
			# If there is not index record to match the count record,
			# the count should be removed.
			db.counts.remove(c)
			continue
		title = c["title"]
		he = list_from_counts(c["availableTexts"]["he"])
		en = list_from_counts(c["availableTexts"]["en"])
		sections = union(he, en)
		for n in sections:
			if i["categories"][0] == "Talmud":
				n = texts.section_to_daf(int(n))
			if "commentaryCategories" in i and i["commentaryCategories"][0] == "Talmud":
				split = n.split(":")
				n = ":".join([texts.section_to_daf(int(n[0]))] + split[1:])
			ref = "%s %s" % (title, n) if n else title
			refs.append(ref)

	return refs
示例#2
0
	def flatten(text, sectionNames):
		text = text or ""
		if len(sectionNames) == 1:
			text = [t if t else "" for t in text]
			# Bandaid for mismatch between text structure, join recursively if text 
			# elements are lists instead of strings.
			return "\n".join([t if isinstance(t, basestring) else "\n".join(t) for t in text])
		flat = ""
		for i in range(len(text)):
			section = section_to_daf(i + 1) if sectionNames[0] == "Daf" else str(i + 1)
			flat += "\n\n%s %s\n\n%s" % (sectionNames[0], section, flatten(text[i], sectionNames[1:]))
		return flat
示例#3
0
		text_total[text["title"]] = 0
		text_order.append(text["title"])
	print text["title"]
	index = t.get_index(text["title"])
	if not index or not index.get("categories"):
		print "No index found for " + text["title"]
		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 = t.section_to_daf(i + 1)
		else:
			chap = i + 1
		ref = text['title'] + " " + str(chap)
		print ref
		try:
			result = t.add_links_from_text(ref, {"text": 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 = t.get_index(text)