mirror of
https://github.com/flibusta-apps/library_updater.git
synced 2025-12-06 07:45:35 +01:00
Fix logging
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from logging import Logger
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import aiomysql
|
import aiomysql
|
||||||
@@ -9,7 +9,13 @@ import asyncpg
|
|||||||
from core.config import env_config
|
from core.config import env_config
|
||||||
|
|
||||||
|
|
||||||
logger = Logger("fl_updater")
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
|
||||||
async def run(cmd) -> tuple[bytes, bytes, Optional[int]]:
|
async def run(cmd) -> tuple[bytes, bytes, Optional[int]]:
|
||||||
@@ -29,6 +35,26 @@ def remove_dots(s: str):
|
|||||||
return s.replace(".", "")
|
return s.replace(".", "")
|
||||||
|
|
||||||
|
|
||||||
|
def fix_annotation_text(text: str) -> str:
|
||||||
|
replace_map = {
|
||||||
|
"<p class=book>": "",
|
||||||
|
'<p class="book">': "",
|
||||||
|
"<p>": "",
|
||||||
|
"</p>": "",
|
||||||
|
" ": "",
|
||||||
|
"[b]": "",
|
||||||
|
"[/b]": "",
|
||||||
|
"[hr]": "",
|
||||||
|
}
|
||||||
|
|
||||||
|
t = text
|
||||||
|
|
||||||
|
for key, value in replace_map:
|
||||||
|
t = t.replace(key, value)
|
||||||
|
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
class FlUpdater:
|
class FlUpdater:
|
||||||
SOURCE: int
|
SOURCE: int
|
||||||
|
|
||||||
@@ -461,7 +487,7 @@ class FlUpdater:
|
|||||||
self.SOURCE,
|
self.SOURCE,
|
||||||
row[0],
|
row[0],
|
||||||
row[1],
|
row[1],
|
||||||
row[2].lstrip("<p class=book>").rstrip("</p>"),
|
fix_annotation_text(row[2]),
|
||||||
]
|
]
|
||||||
|
|
||||||
async with self.mysql_pool.acquire() as conn:
|
async with self.mysql_pool.acquire() as conn:
|
||||||
@@ -543,6 +569,14 @@ class FlUpdater:
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def fix_annotation(row) -> list:
|
||||||
|
return [
|
||||||
|
self.SOURCE,
|
||||||
|
row[0],
|
||||||
|
row[1],
|
||||||
|
fix_annotation_text(row[2]),
|
||||||
|
]
|
||||||
|
|
||||||
async with self.mysql_pool.acquire() as conn:
|
async with self.mysql_pool.acquire() as conn:
|
||||||
async with conn.cursor() as cursor:
|
async with conn.cursor() as cursor:
|
||||||
await cursor.execute("SELECT COUNT(*) FROM libaannotations;")
|
await cursor.execute("SELECT COUNT(*) FROM libaannotations;")
|
||||||
@@ -560,7 +594,7 @@ class FlUpdater:
|
|||||||
|
|
||||||
await self.postgres_pool.executemany(
|
await self.postgres_pool.executemany(
|
||||||
"SELECT update_author_annotation($1, $2, cast($3 as varchar), cast($4 as text));",
|
"SELECT update_author_annotation($1, $2, cast($3 as varchar), cast($4 as text));",
|
||||||
[[self.SOURCE, *row] for row in rows],
|
[fix_annotation(row) for row in rows],
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("Author_annotation_updated!")
|
logger.info("Author_annotation_updated!")
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ class WorkerSettings:
|
|||||||
on_startup = startup
|
on_startup = startup
|
||||||
redis_settings = get_redis_settings()
|
redis_settings = get_redis_settings()
|
||||||
max_jobs = 1
|
max_jobs = 1
|
||||||
job_timeout = 60 * 60
|
job_timeout = 15 * 60
|
||||||
|
|||||||
Reference in New Issue
Block a user