-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbMethods.py
64 lines (56 loc) · 2.08 KB
/
dbMethods.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sqlite3
# Connection Seupt
conn = sqlite3.connect('gephi.db')
c = conn.cursor()
def create_table():
c.execute('CREATE TABLE IF NOT EXISTS GephiNodes(id INTEGER, label TEXT, fan_count INTEGER, handle TEXT )')
c.execute('CREATE TABLE IF NOT EXISTS GephiEdges(source INTEGER, target INTEGER, type TEXT, id INTEGER, weight INTEGER)')
def dynamic_data_entry_Nodes(id, label, fan_count, handle):
c.execute("INSERT INTO GephiNodes (id, label, fan_count, handle) VALUES (?, ?, ?, ?)",
(id, label, fan_count, handle))
conn.commit()
def dynamic_data_entry_Edges(source, target, type, id, weight):
c.execute("INSERT INTO GephiEdges (source, target, type, id, weight) VALUES (?, ?, ?, ?, ?)",
(source, target, type, id, weight))
conn.commit()
def read_from_db_GephiNodes(**kwargs):
if "id" in kwargs:
id = (kwargs["id"], )
c.execute("SELECT * FROM GephiNodes WHERE id=?", id)
data = c.fetchall()
return data
if "label" in kwargs:
label = (kwargs["label"], )
c.execute("SELECT * FROM GephiNodes WHERE label=?", label)
data = c.fetchall()
return data
if "handle" in kwargs:
handle = (kwargs["handle"], )
c.execute("SELECT * FROM GephiNodes WHERE handle=?", handle)
data = c.fetchall()
return data
c.execute("SELECT * FROM GephiNodes")
data = c.fetchall()
return data
def read_from_db_GephiEdges(**kwargs):
if "id" in kwargs:
id = (kwargs["id"], )
c.execute("SELECT * FROM GephiEdges WHERE id=?", id)
data = c.fetchall()
return data
if "source" in kwargs:
source = (kwargs["source"], )
c.execute("SELECT * FROM GephiEdges WHERE source=?", source)
data = c.fetchall()
return data
if "target" in kwargs:
target = (kwargs["target"], )
c.execute("SELECT * FROM GephiEdges WHERE target=?", target)
data = c.fetchall()
return data
c.execute("SELECT * FROM GephiEdges")
data = c.fetchall()
return data
def close_connection():
c.close()
conn.close()