def get_all_toc_locations(title, toc=None):
    if toc is None:
        toc = s.get_toc()
    """
    Finds ALL occurrences of a text title in the toc. Recursively looks through the ToC to find the category paths
    of the given title
    :param title: the title to look for.
    :return: a list of lists of categories leading to the title or an empty array if not found.
    """
    results = []
    for toc_elem in toc:
        #base element, a text- check if title matches.
        if 'title' in toc_elem:
            if toc_elem['title'] == title:
                #if there is a match, append to this recursion's list of results.
                results.append(True)
        #category
        elif 'category' in toc_elem:
            #first go down the tree
            sub_result = get_all_toc_locations(title, toc_elem['contents'])
            #add the current category name to any already-found results (since at this point we are on our way up from the recursion.
            if sub_result:
                for path in sub_result:
                    new_path = [toc_elem['category']] + path if isinstance(path, list) else [toc_elem['category']]
                    results.append(new_path)
    return results
Example #2
0
def generate_texts_toc_sitemap():
	"""
	Creates a sitemap for each text table of contents page.
	"""
	titles = flatten_toc(get_toc())
	urls = ["http://www.sefaria.org/" + Ref(title).url() for title in titles]
	write_urls(urls, "text-toc-sitemap.txt")
Example #3
0
def generate_texts_toc_sitemap():
    """
	Creates a sitemap for each text table of contents page.
	"""
    titles = flatten_toc(get_toc())
    urls = ["http://www.sefaria.org/" + Ref(title).url() for title in titles]
    write_urls(urls, "text-toc-sitemap.txt")
Example #4
0
def get_all_toc_locations(title, toc=None):
    if toc is None:
        toc = s.get_toc()
    """
    Finds ALL occurrences of a text title in the toc. Recursively looks through the ToC to find the category paths
    of the given title
    :param title: the title to look for.
    :return: a list of lists of categories leading to the title or an empty array if not found.
    """
    results = []
    for toc_elem in toc:
        #base element, a text- check if title matches.
        if 'title' in toc_elem:
            if toc_elem['title'] == title:
                #if there is a match, append to this recursion's list of results.
                results.append(True)
        #category
        elif 'category' in toc_elem:
            #first go down the tree
            sub_result = get_all_toc_locations(title, toc_elem['contents'])
            #add the current category name to any already-found results (since at this point we are on our way up from the recursion.
            if sub_result:
                for path in sub_result:
                    new_path = [toc_elem['category']] + path if isinstance(
                        path, list) else [toc_elem['category']]
                    results.append(new_path)
    return results
Example #5
0
def generate_categories_sitemap():
	"""
	Creates sitemap for each category page.
	"""
	toc   = get_toc()
	def cat_paths(toc):
		paths = []
		for t in toc:
			cat = t.get("category", None)
			if cat:
				cat = cat.replace(" ", "%20")
				paths.append(cat)
				subpaths = cat_paths(t["contents"])
				paths = paths + [cat + "/" + sp for sp in subpaths]
		return paths
	paths = cat_paths(toc)
	urls = ["http://www.sefaria.org/" + p for p in paths]
	write_urls(urls, "categories-sitemap.txt")
Example #6
0
def generate_categories_sitemap():
    """
	Creates sitemap for each category page.
	"""
    toc = get_toc()

    def cat_paths(toc):
        paths = []
        for t in toc:
            cat = t.get("category", None)
            if cat:
                cat = cat.replace(" ", "%20")
                paths.append(cat)
                subpaths = cat_paths(t["contents"])
                paths = paths + [cat + "/" + sp for sp in subpaths]
        return paths

    paths = cat_paths(toc)
    urls = ["http://www.sefaria.org/" + p for p in paths]
    write_urls(urls, "categories-sitemap.txt")
Example #7
0
def dashboard(request):
	"""
	Dashboard page -- table view of all content
	"""
	counts = db.counts.find({"title": {"$exists": 1}}, 
		{"title": 1, "flags": 1, "linksCount": 1, "percentAvailable": 1})
	
	toc = get_toc()
	flat_toc = flatten_toc(toc)

	def toc_sort(a):
		try:
			return flat_toc.index(a["title"])
		except:
			return 9999

	counts = sorted(counts, key=toc_sort)

	return render_to_response('dashboard.html',
								{
									"counts": counts,
								},
								RequestContext(request))
Example #8
0
def table_of_contents_api(request):
	return jsonResponse(get_toc())
Example #9
0
 def test_toc_integrity(self):
     toc = s.get_toc()
     self.recur_toc_integrity(toc)
def toc(request):
    return {"toc": get_toc(), "toc_json": get_toc_json()}
Example #11
0
def toc(request):
    return {"toc": get_toc(), "toc_json": get_toc_json()}
Example #12
0
def test_toc_integrity():
    toc = s.get_toc()
    recur_toc_integrity(toc)
Example #13
0
 def test_toc_integrity(self):
     toc = s.get_toc()
     self.recur_toc_integrity(toc)
def toc(request):
	return {"toc": get_toc()}
Example #15
0
def table_of_contents_list_api(reuquest):
    return jsonResponse(get_toc())