Skip to content

Commit 8b8f814

Browse files
committed
Revert "fix a few issues and refresh db connection func"
This reverts commit 09e0a69.
1 parent 50a8ea4 commit 8b8f814

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

pybpsapi.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def __init__(self, category, url: str = "https://bpsapi.rajtech.me/v1/", cache_m
141141
self._con = sqlite3.connect(self.db_path + f"/{self.db_name}.db")
142142
self._cur = self._con.cursor()
143143

144-
self._cur.execute(f"CREATE TABLE IF NOT EXISTS {self.db_table} (title TEXT, category TEXT, data BLOB)")
145-
self._cur.execute(f"INSERT INTO {self.db_table} VALUES (?, ?, ?)",
146-
("circular_list", self.category, pickle.dumps([])))
144+
self._cur.execute("CREATE TABLE IF NOT EXISTS ? (title TEXT, category TEXT, data BLOB)", (self.db_table,))
145+
self._cur.execute("INSERT INTO ? VALUES (?, ?, ?)",
146+
(self.db_table, "circular_list", self.category, pickle.dumps([])))
147147
self._con.commit()
148148

149149
elif cache_method == "pickle":
@@ -167,19 +167,13 @@ def __init__(self, category, url: str = "https://bpsapi.rajtech.me/v1/", cache_m
167167
else:
168168
raise ValueError("Invalid Cache Method")
169169

170-
def refresh_db_con(self):
171-
if not self.cache_method == "database":
172-
return
173-
174-
import sqlite3
175-
176-
self._con = sqlite3.connect(self.db_path + f"/{self.db_name}.db")
177-
self._cur = self._con.cursor()
170+
else:
171+
pass
178172

179173
def get_cache(self) -> list[list]:
180174
if self.cache_method == "database":
181175
self.refresh_db_con()
182-
self._cur.execute(f"SELECT * FROM {self.db_table} WHERE category = ?", (self.category,))
176+
self._cur.execute("SELECT * FROM ? WHERE category = ?", (self.db_table, self.category))
183177
res = self._cur.fetchone()
184178
if res is None:
185179
return []
@@ -212,12 +206,10 @@ def _set_cache(self, data, title: str = "circular_list"):
212206
def _refresh_cache(self):
213207
request = requests.get(self.url + "list", params=self._params)
214208
json = request.json()
215-
216209
try:
217210
json['http_status']
218211
except KeyError:
219212
raise ValueError("Invalid API Response")
220-
221213
if json['http_status'] == 200:
222214
self._set_cache(json['data'])
223215

@@ -248,10 +240,13 @@ def check(self) -> list[dict] or list[None]:
248240

249241

250242
class CircularCheckerGroup:
251-
def __init__(self, *args, debug: bool = False):
243+
def __init__(self, *args, **kwargs):
252244
self._checkers = []
253245

254-
self.debug = debug
246+
if kwargs.get("debug"):
247+
self.debug = True
248+
else:
249+
self.debug = False
255250

256251
for arg in args:
257252
if type(arg) != CircularChecker:
@@ -268,8 +263,7 @@ def add(self, checker: CircularChecker, *args: CircularChecker):
268263
raise ValueError("Invalid CircularChecker Object")
269264
self._checkers.append(arg)
270265

271-
def create(self, category, url: str = "https://bpsapi.rajtech.me/v1/", cache_method=None, debug: bool = False,
272-
**kwargs):
266+
def create(self, category, url: str = "https://bpsapi.rajtech.me/v1/", cache_method=None, debug: bool = False, **kwargs):
273267
checker = CircularChecker(category, url, cache_method, debug, **kwargs)
274268
self._checkers.append(checker)
275269

0 commit comments

Comments
 (0)