scientific-programming-exer.../exam/ex01/main.py

35 lines
970 B
Python

import logging
logging.basicConfig(level=logging.DEBUG)
from cache import get_cache
from receive import receive_links, receive_link_graph
from dijkstra import prepare_dijkstra, dijkstra
from connectivity import shortest_path
from graph import DijkstraHelper
from db_util import get_page_id, get_page_title
cache = get_cache()
receive_link_graph("Angela_Merkel", cache, 2, lang="en")
cursor = cache.cursor()
cursor.execute("SELECT COUNT(source) FROM links")
print(cursor.fetchall())
#prepare_dijkstra(cache)
#dijkstra("Angela_Merkel", cache)
#
angela = get_page_id("Angela_Merkel", cache)
dijkstra = DijkstraHelper.from_db(cache)
dijkstra.dijkstra(angela)
dijkstra.write_back(cache)
#print({k:v for k,v in dijkstra._nodes.items() if v != float("inf")})
print([get_page_title(id_, cache) for id_ in shortest_path("Angela_Merkel", "Germany", cache)])
print([get_page_title(id_, cache) for id_ in shortest_path("Angela_Merkel", "2012_Nobel_Peace_Prize", cache)])