-
Notifications
You must be signed in to change notification settings - Fork 1
/
DB_comms.py
30 lines (25 loc) · 1 KB
/
DB_comms.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 MySQLdb as mdb
from webVisit import webVisit
class DB_comms:
def __init__(self):
self.connection = mdb.connect(host="192.168.0.6", user="bendeco", passwd = "password", db = "crawlbot")
self.cursor = self.connection.cursor()
self.visit = webVisit()
def insert(self, url, title):
query = "INSERT IGNORE into Indexed (title, url) values"
query += "(\'" + mdb.escape_string(title) + "\', \'"
query += mdb.escape_string(url) + "\')"
self.cursor.execute(query)
def insert_auth(self, url, title):
query = "SELECT COUNT(domain) FROM Auth WHERE domain = '"
query += "" + mdb.escape_string(url) +"'"
self.cursor.execute(query)
num = self.cursor.fetchone()
if num[0] > 0:
query = "UPDATE Auth SET counter=counter+1 WHERE "
query += "domain = '" + mdb.escape_string(url) + "'"
self.cursor.execute(query)
else:
query = "INSERT INTO Auth (domain, title) "
query += "VALUES('" + mdb.escape_string(url) + "', '" + mdb.escape_string(title) + "')"
self.cursor.execute(query)