|
|
@@ -20,24 +20,25 @@ import jaconv |
|
|
import requests |
|
|
import requests |
|
|
from eloquent import DatabaseManager, Model |
|
|
from eloquent import DatabaseManager, Model |
|
|
|
|
|
|
|
|
|
|
|
from db.config import DB |
|
|
from db.models import Comment, Tag, User, Video, VideoHistory, VideoTag |
|
|
from db.models import Comment, Tag, User, Video, VideoHistory, VideoTag |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main ( |
|
|
def main ( |
|
|
) -> None: |
|
|
) -> None: |
|
|
config: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql', |
|
|
|
|
|
'host': 'localhost', |
|
|
|
|
|
'database': 'nizika_nico', |
|
|
|
|
|
'user': os.environ['MYSQL_USER'], |
|
|
|
|
|
'password': os.environ['MYSQL_PASS'], |
|
|
|
|
|
'prefix': '' } } |
|
|
|
|
|
db = DatabaseManager (config) |
|
|
|
|
|
Model.set_connection_resolver (db) |
|
|
|
|
|
|
|
|
|
|
|
now = datetime.now () |
|
|
now = datetime.now () |
|
|
|
|
|
|
|
|
api_data = search_nico_by_tags (['伊地知ニジカ', 'ぼざろクリーチャーシリーズ', 'ぼざろクリーチャーシリーズ外伝']) |
|
|
|
|
|
update_tables (api_data, now) |
|
|
|
|
|
|
|
|
api_data = search_nico_by_tags (['伊地知ニジカ', |
|
|
|
|
|
'ぼざろクリーチャーシリーズ', |
|
|
|
|
|
'ぼざろクリーチャーシリーズ外伝']) |
|
|
|
|
|
|
|
|
|
|
|
DB.begin_transaction () |
|
|
|
|
|
try: |
|
|
|
|
|
update_tables (api_data, now) |
|
|
|
|
|
DB.commit () |
|
|
|
|
|
except Exception: |
|
|
|
|
|
DB.rollback () |
|
|
|
|
|
raise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_tables ( |
|
|
def update_tables ( |
|
|
@@ -211,15 +212,6 @@ def search_nico_by_tags ( |
|
|
return result_data |
|
|
return result_data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DbConfig (TypedDict): |
|
|
|
|
|
driver: str |
|
|
|
|
|
host: str |
|
|
|
|
|
database: str |
|
|
|
|
|
user: str |
|
|
|
|
|
password: str |
|
|
|
|
|
prefix: str |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoSearchParam (TypedDict): |
|
|
class VideoSearchParam (TypedDict): |
|
|
q: str |
|
|
q: str |
|
|
targets: str |
|
|
targets: str |
|
|
|