Common commit
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import json
|
||||
import os.path
|
||||
|
||||
from modules.civit.Civit import Civit
|
||||
from modules.civit.datamodel import Creator, Tag, Model
|
||||
from modules.civit.fetch import Fetch
|
||||
from modules.shared.DatabaseSqlite import SQLiteDatabase
|
||||
from shell.Handlers.ABS import Handler
|
||||
from modules.civit.client import Client
|
||||
|
||||
@@ -11,25 +15,52 @@ class CivitHandler(Handler):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.forwarding_table: dict[str, Handler] = {
|
||||
'fetch': FetchHandler(self)
|
||||
'fetch': FetchHandler(self),
|
||||
'save': SaveHandler(self)
|
||||
}
|
||||
self.handle_table: dict = {
|
||||
'init': self._init,
|
||||
}
|
||||
self.client: Client | None = None
|
||||
self.client: Civit | None = None
|
||||
|
||||
|
||||
def _init(self, command: list[str], pos=0):
|
||||
keys, args = self.parse_arguments(command[pos:], ['path', 'key'])
|
||||
keys, args = self.parse_arguments(command[pos:], ['path', 'key', 'dbpath'])
|
||||
self._check_arg(keys, 'path')
|
||||
self.client = Client(keys['path'], keys['key'])
|
||||
if not keys['dbpath']: keys['dbpath'] = keys['path']
|
||||
db = SQLiteDatabase(path=keys['dbpath'], name='data')
|
||||
self.client = Civit(db, path=keys['path'], api_key=keys['key'])
|
||||
self.succeed = True
|
||||
|
||||
class SaveHandler(Handler):
|
||||
def __init__(self, parent):
|
||||
super().__init__()
|
||||
self.parent: CivitHandler = parent
|
||||
self.forwarding_table: dict[str, Handler] = {
|
||||
}
|
||||
self.handle_table: dict = {
|
||||
'creators': self._creators,
|
||||
'tags': self._tags,
|
||||
'models': self._models,
|
||||
'images': self._images,
|
||||
}
|
||||
|
||||
def _creators(self, command: list[str], pos=0):
|
||||
self.parent.client.from_fetch('creator', Creator)
|
||||
self.succeed = True
|
||||
|
||||
def _tags(self, command: list[str], pos=0):
|
||||
self.parent.client.from_fetch('tag', Tag)
|
||||
self.succeed = True
|
||||
|
||||
def _models(self, command: list[str], pos=0):
|
||||
self.parent.client.from_fetch('model', Model)
|
||||
self.succeed = True
|
||||
|
||||
def _images(self, command: list[str], pos=0): raise NotImplemented
|
||||
|
||||
|
||||
class FetchHandler(Handler):
|
||||
|
||||
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__()
|
||||
self.parent: CivitHandler = parent
|
||||
@@ -51,7 +82,7 @@ class FetchHandler(Handler):
|
||||
keys, args = self.parse_arguments(command[pos:], ['entity'])
|
||||
self._check_arg(keys, 'entity')
|
||||
|
||||
res = Fetch.load(self.parent.client, keys['entity'])
|
||||
res = Fetch.load(self.parent.client.client, keys['entity'])
|
||||
for r in res: print(r)
|
||||
self.succeed = True
|
||||
|
||||
@@ -59,24 +90,24 @@ class FetchHandler(Handler):
|
||||
|
||||
def _creators_raw(self, command: list[str], pos=0):
|
||||
keys, args = self.parse_arguments(command[pos:], ['page', 'limit', 'query'])
|
||||
res = self.parent.client.get_creators_raw(page=keys['page'], limit=keys['limit'], query=keys['query'])
|
||||
res = self.parent.client.client.get_creators_raw(page=keys['page'], limit=keys['limit'], query=keys['query'])
|
||||
print(res)
|
||||
self.succeed = True
|
||||
|
||||
def _creators(self, command: list[str], pos=0):
|
||||
res = Fetch.creators(self.parent.client)
|
||||
res = self.parent.client.fetcher.creators()
|
||||
for r in res: print(r)
|
||||
self.succeed = True
|
||||
|
||||
|
||||
def _tags_raw(self, command: list[str], pos=0):
|
||||
keys, args = self.parse_arguments(command[pos:], ['page', 'limit', 'query'])
|
||||
res = self.parent.client.get_tags_raw(page=keys['page'], limit=keys['limit'], query=keys['query'])
|
||||
res = self.parent.client.client.get_tags_raw(page=keys['page'], limit=keys['limit'], query=keys['query'])
|
||||
print(res)
|
||||
self.succeed = True
|
||||
|
||||
def _tags(self, command: list[str], pos=0):
|
||||
res = Fetch.tags(self.parent.client)
|
||||
res = self.parent.client.fetcher.tags()
|
||||
for r in res: print(r)
|
||||
self.succeed = True
|
||||
|
||||
@@ -87,7 +118,7 @@ class FetchHandler(Handler):
|
||||
|
||||
def _images(self, command: list[str], pos=0):
|
||||
keys, args = self.parse_arguments(command[pos:], ['start'])
|
||||
res = Fetch.images(self.parent.client, start_with=keys['start'])
|
||||
res = Fetch.images(self.parent.client.client, start_with=keys['start'])
|
||||
for r in res: print(r)
|
||||
self.succeed = True
|
||||
|
||||
@@ -101,7 +132,7 @@ class FetchHandler(Handler):
|
||||
keys, args = self.parse_arguments(command[pos:], ['entity', 'top', 'dump'])
|
||||
self._check_arg(keys, 'entity')
|
||||
if keys['entity'] in entities:
|
||||
res = Fetch.datamodel(self.parent.client, entities[keys['entity']], keys['top'] or 10)
|
||||
res = Fetch.datamodel(self.parent.client.client, entities[keys['entity']], keys['top'] or 10)
|
||||
print(json.dumps(res, indent=2, ensure_ascii=False))
|
||||
if keys['dump']:
|
||||
with open(keys['dump'], 'w') as f:
|
||||
|
||||
Reference in New Issue
Block a user