-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
功能变动: - 完全移除 MongoDB 相关逻辑和迁移脚本
- Loading branch information
Showing
19 changed files
with
260 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
[mongo] | ||
host = "localhost" | ||
port = 27017 | ||
database = "jfetcher" | ||
|
||
[jianshu_postgres] | ||
host = "localhost" | ||
port = 5432 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from asyncio import run as asyncio_run | ||
from datetime import date | ||
|
||
from jkit.article import Article | ||
from jkit.config import CONFIG | ||
from jkit.exceptions import ResourceUnavailableError | ||
from sshared.logging import Logger | ||
|
||
from utils.postgres import get_jianshu_conn | ||
|
||
START_DATE = date(2024, 10, 30) | ||
|
||
CONFIG.data_validation.enabled = False | ||
logger = Logger() | ||
|
||
|
||
async def main() -> None: | ||
logger.info(f"准备修复 {START_DATE} 至今的数据") | ||
|
||
conn = await get_jianshu_conn() | ||
|
||
cursor = await conn.execute( | ||
"SELECT slug FROM article_earning_ranking_records " | ||
"WHERE date >= %s AND slug IS NOT NULL AND author_slug IS NULL " | ||
"ORDER BY date, ranking;", | ||
(START_DATE,), | ||
) | ||
|
||
async for item in cursor: | ||
article = Article.from_slug(item[0]) | ||
|
||
try: | ||
author_slug = (await article.info).author_info.slug | ||
except ResourceUnavailableError: | ||
logger.warn(f"文章 {article.slug} 已删除,跳过数据获取") | ||
continue | ||
|
||
await conn.execute( | ||
"UPDATE article_earning_ranking_records SET author_slug = %s " | ||
"WHERE slug = %s;", | ||
(author_slug, article.slug), | ||
) | ||
logger.debug(f"已成功更新 {article.slug} 的 author_slug 字段为 {author_slug}") | ||
|
||
logger.info("数据修复完成") | ||
|
||
|
||
asyncio_run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.