|
|
|
@ -1,11 +1,17 @@ |
|
|
|
import sqlite3 |
|
|
|
import os |
|
|
|
import re |
|
|
|
import update |
|
|
|
# https://stackoverflow.com/a/5365533 |
|
|
|
osp = os.path |
|
|
|
DB_PATH = osp.join(osp.dirname(__file__),'ext.db') |
|
|
|
ext_database = sqlite3.connect(DB_PATH) |
|
|
|
def init_db(): |
|
|
|
cur = ext_database.cursor() |
|
|
|
cur.execute('CREATE TABLE "updates" ( `ext` TEXT, `update_time` INTEGER, `file_count` INTEGER, PRIMARY KEY(`ext`) )') |
|
|
|
def regexp(expr, item): |
|
|
|
return re.search(expr,item) is not None |
|
|
|
ext_database.create_function("REGEXP", 2, regexp) |
|
|
|
class Searcher: |
|
|
|
def __init__(self,ext): |
|
|
|
self.cur = ext_database.cursor() |
|
|
|
@ -22,4 +28,8 @@ class Searcher: |
|
|
|
def _commit_(self): |
|
|
|
ext_database.commit() |
|
|
|
def search(query,regex=False): |
|
|
|
pass |
|
|
|
if regex: |
|
|
|
self.cur.execute('SELECT * FROM ? WHERE name REGEXP ?',[self.ext,query]) |
|
|
|
else: |
|
|
|
self.cur.execute('SELECT * FROM ? WHERE name LIKE ?',[self.ext,query]) |
|
|
|
return self.cur.fetchall() |