fixed some bugs

This commit is contained in:
Daniel Knüttel 2019-02-25 14:23:09 +01:00
parent a623cf8497
commit a7539c1cad
3 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,6 @@
config = {
"use_sqlite": True
"use_sqlite": False
, "mysql_server": "172.17.0.2"
, "mysql_user": "wikipedia"
, "mysql_password": "wikipediastuff"

View File

@ -49,7 +49,13 @@ class DijkstraHelper(object):
def write_back(self, connection):
cursor = connection.cursor()
cursor.execute(sql.statements["delete_dijkstra"])
cursor.executemany(sql.statements["insert_dijkstra_values"], list(self._nodes.items()))
def sqlize(v):
if(config["use_sqlite"]):
return v
if(v == float("inf")):
return 2147483647
cursor.executemany(sql.statements["insert_dijkstra_values"], [(k, sqlize(v)) for k,v in self._nodes.items()])

View File

@ -29,4 +29,4 @@ angela = get_page_id("Angela_Merkel", cache)
dijkstra = DijkstraHelper.from_db(cache)
dijkstra.dijkstra(angela)
dijkstra.write_back(cache)
print(dijkstra._nodes)
print({k:v for k,v in dijkstra._nodes.items() if v != float("inf")})