def read(path): trie = Trie() parser = Parser() graph = Graph() # Adding words into the trie and links into the graph: for root, dirs, files in os.walk(path): for path in files: if path.endswith(".html") or path.endswith(".htm"): current = os.path.join(root, path) u = graph.insert_vertex(current) links, words = parser.parse(current) for link in links: v = graph.insert_vertex(link) graph.insert_edge(u, v) for word in words: trie.add(word.lower(), current) return trie, graph
def create_graph(currencies: Set[Currency]) -> Graph: """ Creates a directed graph representing currencies. :param currencies: the currencies to insert in the graph :return: the graph representing currencies """ g = Graph(directed=True) for currency in currencies: if currency._code not in g.vertices(): g.insert_vertex(currency._code) for c in currencies: code = c._code try: change = currency.get_change(code) if code not in g.vertices(): g.insert_vertex(code) g.insert_edge(currency._code, code, round(change, 2)) except KeyError: continue return g