-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfriendpath.py
30 lines (23 loc) · 857 Bytes
/
friendpath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sqlite3
import networkx as nx
def sqlite_connect():
connection = sqlite3.connect("data")
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
return connection,cursor
def main():
print "connecting..."
connection,cursor = sqlite_connect()
print "connection established!"
print "creating social network..."
G=nx.Graph()
for row in cursor.execute('SELECT p.url as purl,f.friendurl as furl FROM friends f inner join persons p on f.personid=p.personid'):
#print "purl=%s furl=%s" % (row["purl"],row["furl"])
G.add_edge(row["purl"],row["furl"])
connection.rollback()
connection.close()
print "social network successfull created!"
path = nx.shortest_path(G, "<url_from>", "<url_to>", weight=1)
print path
if __name__ == '__main__':
main()