-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbhandler.py
28 lines (22 loc) · 1.04 KB
/
dbhandler.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
import sqlite3
from datetime import datetime
class DBHandler(object):
def __init__(self):
self.conn = sqlite3.connect("data.db")
self.cursor = self.conn.cursor()
self.today = datetime.now().strftime("%Y-%m-%d")
def get_all_link(self):
self.cursor.execute('SELECT DISTINCT jobname,company FROM jobinfo')
return self.cursor.fetchall()
def in_db(self, jobname, company):
return (jobname, company) in self.get_all_link()
def savedata(self, data):
for item in data:
if not self.in_db(item['jobname'], item['company']):
item['etldate'] = self.today
self.cursor.execute("INSERT INTO jobinfo VALUES ('%s','%s','%s','%s','%s','%s','%s')" % (
item['media'], item['jobname'], item['joblink'], item['company'], item['location'], item['salary'], item['etldate']))
self.conn.commit()
def getdata(self):
self.cursor.execute("SELECT * FROM jobinfo WHERE etldate='%s'" % self.today)
return self.cursor.fetchall()