fixed some bugs
This commit is contained in:
parent
a623cf8497
commit
a7539c1cad
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
"use_sqlite": True
|
"use_sqlite": False
|
||||||
, "mysql_server": "172.17.0.2"
|
, "mysql_server": "172.17.0.2"
|
||||||
, "mysql_user": "wikipedia"
|
, "mysql_user": "wikipedia"
|
||||||
, "mysql_password": "wikipediastuff"
|
, "mysql_password": "wikipediastuff"
|
||||||
|
|
|
@ -49,7 +49,13 @@ class DijkstraHelper(object):
|
||||||
def write_back(self, connection):
|
def write_back(self, connection):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute(sql.statements["delete_dijkstra"])
|
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()])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,4 +29,4 @@ angela = get_page_id("Angela_Merkel", cache)
|
||||||
dijkstra = DijkstraHelper.from_db(cache)
|
dijkstra = DijkstraHelper.from_db(cache)
|
||||||
dijkstra.dijkstra(angela)
|
dijkstra.dijkstra(angela)
|
||||||
dijkstra.write_back(cache)
|
dijkstra.write_back(cache)
|
||||||
print(dijkstra._nodes)
|
print({k:v for k,v in dijkstra._nodes.items() if v != float("inf")})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user