43 lines
729 B
Python
43 lines
729 B
Python
import json
|
|
import sqlite3
|
|
|
|
from json import loads as json_loads
|
|
|
|
|
|
class Loader:
|
|
def load(self, file: str):
|
|
raise NotImplementedError()
|
|
|
|
def get_entry(self) -> object:
|
|
raise NotImplementedError()
|
|
|
|
|
|
class JSONLoader(Loader):
|
|
data = None
|
|
|
|
def load(self, file: str):
|
|
self.data = json.load(open(file))
|
|
|
|
def get_entry(self) -> dict:
|
|
for entry in self.data:
|
|
yield entry
|
|
|
|
|
|
class SQLiteLoader(Loader):
|
|
conn = None
|
|
|
|
def load(self, file: str):
|
|
self.conn = sqlite3.connect(file)
|
|
|
|
def get_entry(self) -> dict:
|
|
cursor = self.conn.cursor()
|
|
cursor.execute("SELECT * FROM log_entry")
|
|
for seq, timestamp, json in cursor.fetchall():
|
|
yield json_loads(json)
|
|
|
|
|
|
LOADERS = {
|
|
"json": JSONLoader,
|
|
"sqlite": SQLiteLoader
|
|
}
|