Skip to content

Commit fc305ea

Browse files
committed
adding new fields for link counts and linking back boolean
1 parent e24b216 commit fc305ea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

runner.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from bottle import route, run, template
22
from neo4j.v1 import GraphDatabase, basic_auth
3+
from random import *
34

45
driver = GraphDatabase.driver('bolt://localhost',auth=basic_auth("neo4j", "password"))
56

@@ -15,11 +16,19 @@ def get_graph(article):
1516
rels = []
1617
i = 0
1718
for record in results:
18-
nodes.append({"title": record["link"], "url": generateUrl(record["link"])})
19+
# nodes.append({"title": record["link"], "url": generateUrl(record["link"]), "rel_count": get_links_count(record["link"])})
20+
nodes.append({"title": record["link"], "url": generateUrl(record["link"]), "rel_count": randint(1, 100), "rev_link": "true"})
1921
target = i
2022
i += 1
2123
return dict(pages=nodes)
2224

25+
def get_links_count(article):
26+
db = get_db()
27+
query = 'MATCH (p:Page {title:"%s"})<-[:Link]-(o:Page) RETURN count(o)' % article.replace("_"," ")
28+
result = db.run(query)
29+
return result
30+
31+
2332
def generateUrl(title):
2433
url_root = "https://en.wikipedia.org/wiki/"
2534
return url_root+title.replace(" ","_")

0 commit comments

Comments
 (0)