updatePublishedMsgDaily.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. """
  2. @author: luojunhui
  3. @description: update daily information into official articles v2
  4. """
  5. import time
  6. import json
  7. import traceback
  8. import urllib.parse
  9. from tqdm import tqdm
  10. from datetime import datetime
  11. from argparse import ArgumentParser
  12. from applications import PQMySQL, WeixinSpider, Functions, log, bot, aiditApi, longArticlesMySQL, \
  13. create_feishu_columns_sheet
  14. from applications.const import updatePublishedMsgTaskConst
  15. ARTICLE_TABLE = "official_articles_v2"
  16. const = updatePublishedMsgTaskConst()
  17. spider = WeixinSpider()
  18. functions = Functions()
  19. def generate_bot_columns():
  20. """
  21. 生成列
  22. :return:
  23. """
  24. columns = [
  25. create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="name", display_name="公众号名称"),
  26. create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="ghId", display_name="ghId"),
  27. create_feishu_columns_sheet(sheet_type="number", sheet_name="follower_count", display_name="粉丝数"),
  28. create_feishu_columns_sheet(sheet_type="date", sheet_name="account_init_timestamp",
  29. display_name="账号接入系统时间"),
  30. create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="using_status", display_name="利用状态")
  31. ]
  32. return columns
  33. def get_account_using_status():
  34. """
  35. 获取正在 using 的 ghid
  36. :return:
  37. """
  38. sql = "SELECT gh_id FROM long_articles_publishing_accounts WHERE is_using = 1;"
  39. gh_id_tuple = PQMySQL().select(sql)
  40. gh_id_list = [
  41. i[0] for i in gh_id_tuple
  42. ]
  43. return set(gh_id_list)
  44. def get_accounts():
  45. """
  46. 从 aigc 数据库中获取目前处于发布状态的账号
  47. :return:
  48. "name": line[0],
  49. "ghId": line[1],
  50. "follower_count": line[2],
  51. "account_init_time": int(line[3] / 1000),
  52. "account_type": line[4], # 订阅号 or 服务号
  53. "account_auth": line[5]
  54. """
  55. using_account_set = get_account_using_status()
  56. account_list_with_out_using_status = aiditApi.get_publish_account_from_aigc()
  57. only_auto_reply_accounts_set = aiditApi.get_only_auto_reply_accounts()
  58. account_list = []
  59. for item in account_list_with_out_using_status:
  60. if item['account_id'] in only_auto_reply_accounts_set:
  61. continue
  62. if item['ghId'] in using_account_set:
  63. item['using_status'] = 1
  64. else:
  65. item['using_status'] = 0
  66. account_list.append(item)
  67. subscription_account = [i for i in account_list if i['account_type'] in const.SUBSCRIBE_TYPE_SET]
  68. server_account = [i for i in account_list if i['account_type'] == const.SERVICE_TYPE]
  69. return subscription_account, server_account
  70. def insert_each_msg(db_client, account_info, account_name, msg_list):
  71. """
  72. 把消息数据更新到数据库中
  73. :param account_info:
  74. :param db_client:
  75. :param account_name:
  76. :param msg_list:
  77. :return:
  78. """
  79. gh_id = account_info['ghId']
  80. for info in msg_list:
  81. baseInfo = info.get("BaseInfo", {})
  82. appMsgId = info.get("AppMsg", {}).get("BaseInfo", {}).get("AppMsgId", None)
  83. createTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("CreateTime", None)
  84. updateTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("UpdateTime", None)
  85. Type = info.get("AppMsg", {}).get("BaseInfo", {}).get("Type", None)
  86. detail_article_list = info.get("AppMsg", {}).get("DetailInfo", [])
  87. if detail_article_list:
  88. for article in detail_article_list:
  89. title = article.get("Title", None)
  90. Digest = article.get("Digest", None)
  91. ItemIndex = article.get("ItemIndex", None)
  92. ContentUrl = article.get("ContentUrl", None)
  93. SourceUrl = article.get("SourceUrl", None)
  94. CoverImgUrl = article.get("CoverImgUrl", None)
  95. CoverImgUrl_1_1 = article.get("CoverImgUrl_1_1", None)
  96. CoverImgUrl_235_1 = article.get("CoverImgUrl_235_1", None)
  97. ItemShowType = article.get("ItemShowType", None)
  98. IsOriginal = article.get("IsOriginal", None)
  99. ShowDesc = article.get("ShowDesc", None)
  100. show_stat = Functions().show_desc_to_sta(ShowDesc)
  101. ori_content = article.get("ori_content", None)
  102. show_view_count = show_stat.get("show_view_count", 0)
  103. show_like_count = show_stat.get("show_like_count", 0)
  104. show_zs_count = show_stat.get("show_zs_count", 0)
  105. show_pay_count = show_stat.get("show_pay_count", 0)
  106. wx_sn = ContentUrl.split("&sn=")[1].split("&")[0] if ContentUrl else None
  107. status = account_info['using_status']
  108. info_tuple = (
  109. gh_id,
  110. account_name,
  111. appMsgId,
  112. title,
  113. Type,
  114. createTime,
  115. updateTime,
  116. Digest,
  117. ItemIndex,
  118. ContentUrl,
  119. SourceUrl,
  120. CoverImgUrl,
  121. CoverImgUrl_1_1,
  122. CoverImgUrl_235_1,
  123. ItemShowType,
  124. IsOriginal,
  125. ShowDesc,
  126. ori_content,
  127. show_view_count,
  128. show_like_count,
  129. show_zs_count,
  130. show_pay_count,
  131. wx_sn,
  132. json.dumps(baseInfo, ensure_ascii=False),
  133. Functions().str_to_md5(title),
  134. status
  135. )
  136. try:
  137. insert_sql = f"""
  138. INSERT INTO {ARTICLE_TABLE}
  139. (ghId, accountName, appMsgId, title, Type, createTime, updateTime, Digest, ItemIndex, ContentUrl, SourceUrl, CoverImgUrl, CoverImgUrl_1_1, CoverImgUrl_255_1, ItemShowType, IsOriginal, ShowDesc, ori_content, show_view_count, show_like_count, show_zs_count, show_pay_count, wx_sn, baseInfo, title_md5, status)
  140. values
  141. (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
  142. """
  143. db_client.update(sql=insert_sql, params=info_tuple)
  144. log(
  145. task="updatePublishedMsgDaily",
  146. function="insert_each_msg",
  147. message="插入文章数据成功",
  148. data={
  149. "info": info_tuple
  150. }
  151. )
  152. except Exception as e:
  153. try:
  154. update_sql = f"""
  155. UPDATE {ARTICLE_TABLE}
  156. SET show_view_count = %s, show_like_count=%s
  157. WHERE wx_sn = %s;
  158. """
  159. db_client.update(sql=update_sql,
  160. params=(show_view_count, show_like_count, wx_sn))
  161. log(
  162. task="updatePublishedMsgDaily",
  163. function="insert_each_msg",
  164. message="更新文章数据成功",
  165. data={
  166. "wxSn": wx_sn,
  167. "likeCount": show_like_count,
  168. "viewCount": show_view_count
  169. }
  170. )
  171. except Exception as e:
  172. log(
  173. task="updatePublishedMsgDaily",
  174. function="insert_each_msg",
  175. message="更新文章失败, 报错原因是: {}".format(e),
  176. status="fail"
  177. )
  178. continue
  179. def update_each_account(db_client, account_info, account_name, latest_update_time, cursor=None):
  180. """
  181. 更新每一个账号信息
  182. :param account_info:
  183. :param account_name:
  184. :param cursor:
  185. :param latest_update_time: 最新更新时间
  186. :param db_client: 数据库连接信息
  187. :return: None
  188. """
  189. gh_id = account_info['ghId']
  190. response = WeixinSpider().update_msg_list(ghId=gh_id, index=cursor)
  191. msg_list = response.get("data", {}).get("data", {})
  192. if msg_list:
  193. # do
  194. last_article_in_this_msg = msg_list[-1]
  195. last_time_stamp_in_this_msg = last_article_in_this_msg['AppMsg']['BaseInfo']['UpdateTime']
  196. last_url = last_article_in_this_msg['AppMsg']['DetailInfo'][0]['ContentUrl']
  197. resdata = WeixinSpider().get_account_by_url(last_url)
  198. check_id = resdata['data'].get('data', {}).get('wx_gh')
  199. if check_id == gh_id:
  200. insert_each_msg(
  201. db_client=db_client,
  202. account_info=account_info,
  203. account_name=account_name,
  204. msg_list=msg_list
  205. )
  206. if last_time_stamp_in_this_msg > latest_update_time:
  207. next_cursor = response['data']['next_cursor']
  208. return update_each_account(
  209. db_client=db_client,
  210. account_info=account_info,
  211. account_name=account_name,
  212. latest_update_time=latest_update_time,
  213. cursor=next_cursor
  214. )
  215. log(
  216. task="updatePublishedMsgDaily",
  217. function="update_each_account",
  218. message="账号文章更新成功",
  219. data=response
  220. )
  221. else:
  222. log(
  223. task="updatePublishedMsgDaily",
  224. function="update_each_account",
  225. message="账号文章更新失败",
  226. status="fail",
  227. data=response
  228. )
  229. return
  230. def check_account_info(db_client, gh_id, account_name):
  231. """
  232. 通过 gh_id查询视频信息
  233. :param account_name:
  234. :param db_client:
  235. :param gh_id:
  236. :return:
  237. """
  238. sql = f"""
  239. SELECT accountName, updateTime
  240. FROM {ARTICLE_TABLE}
  241. WHERE ghId = '{gh_id}'
  242. ORDER BY updateTime DESC LIMIT 1;
  243. """
  244. result = db_client.select(sql)
  245. if result:
  246. old_account_name, update_time = result[0]
  247. return {
  248. "account_name": old_account_name,
  249. "update_time": update_time,
  250. "account_type": "history"
  251. }
  252. else:
  253. return {
  254. "account_name": account_name,
  255. "update_time": int(time.time()) - 30 * 24 * 60 * 60,
  256. "account_type": "new"
  257. }
  258. def update_single_account(db_client, account_info):
  259. """
  260. :param account_info:
  261. :param db_client:
  262. :return:
  263. """
  264. gh_id = account_info['ghId']
  265. account_name = account_info['name']
  266. account_detail = check_account_info(db_client, gh_id, account_name)
  267. account_name = account_detail['account_name']
  268. update_time = account_detail['update_time']
  269. update_each_account(
  270. db_client=db_client,
  271. account_info=account_info,
  272. account_name=account_name,
  273. latest_update_time=update_time
  274. )
  275. def check_single_account(db_client, account_item):
  276. """
  277. 校验每个账号是否更新
  278. :param db_client:
  279. :param account_item:
  280. :return: True / False
  281. """
  282. gh_id = account_item['ghId']
  283. account_type = account_item['account_type']
  284. today_str = datetime.today().strftime("%Y-%m-%d")
  285. today_date_time = datetime.strptime(today_str, "%Y-%m-%d")
  286. today_timestamp = today_date_time.timestamp()
  287. sql = f"""
  288. SELECT updateTime
  289. FROM {ARTICLE_TABLE}
  290. WHERE ghId = '{gh_id}'
  291. ORDER BY updateTime
  292. DESC
  293. LIMIT 1;
  294. """
  295. try:
  296. latest_update_time = db_client.select(sql)[0][0]
  297. # 判断该账号当天发布的文章是否被收集
  298. if account_type in const.SUBSCRIBE_TYPE_SET:
  299. if int(latest_update_time) > int(today_timestamp):
  300. return True
  301. else:
  302. return False
  303. else:
  304. if int(latest_update_time) > int(today_timestamp) - 7 * 24 * 3600:
  305. return True
  306. else:
  307. return False
  308. except Exception as e:
  309. print("updateTime Error -- {}".format(e))
  310. return False
  311. def update_job():
  312. """
  313. 更新任务
  314. :return:
  315. """
  316. try:
  317. db_client = PQMySQL()
  318. except Exception as e:
  319. error_msg = traceback.format_exc()
  320. bot(
  321. title="更新文章任务连接数据库失败",
  322. detail={
  323. "error": e,
  324. "msg": error_msg
  325. }
  326. )
  327. return
  328. sub_accounts, server_accounts = get_accounts()
  329. s_count = 0
  330. f_count = 0
  331. for sub_item in tqdm(sub_accounts):
  332. try:
  333. update_single_account(db_client, sub_item)
  334. s_count += 1
  335. time.sleep(5)
  336. except Exception as e:
  337. f_count += 1
  338. log(
  339. task="updatePublishedMsgDaily",
  340. function="update_job",
  341. message="单个账号文章更新失败, 报错信息是: {}".format(e),
  342. status="fail",
  343. )
  344. log(
  345. task="updatePublishedMsgDaily",
  346. function="update_job",
  347. message="订阅号更新完成",
  348. data={
  349. "success": s_count,
  350. "fail": f_count
  351. }
  352. )
  353. if f_count / (s_count + f_count) > 0.3:
  354. bot(
  355. title="订阅号超过 30% 的账号更新失败",
  356. detail={
  357. "success": s_count,
  358. "fail": f_count,
  359. "failRate": f_count / (s_count + f_count)
  360. }
  361. )
  362. bot(
  363. title="更新每日发布文章任务完成通知",
  364. detail={
  365. "msg": "订阅号更新完成",
  366. "finish_time": datetime.today().__str__()
  367. },
  368. mention=False
  369. )
  370. for sub_item in tqdm(server_accounts):
  371. try:
  372. update_single_account(db_client, sub_item)
  373. time.sleep(5)
  374. except Exception as e:
  375. print(e)
  376. bot(
  377. title="更新每日发布文章任务完成通知",
  378. detail={
  379. "msg": "服务号更新完成",
  380. "finish_time": datetime.today().__str__()
  381. },
  382. mention=False
  383. )
  384. def check_job():
  385. """
  386. 校验任务
  387. :return:
  388. """
  389. try:
  390. db_client = PQMySQL()
  391. except Exception as e:
  392. error_msg = traceback.format_exc()
  393. bot(
  394. title="校验更新文章任务连接数据库失败",
  395. detail={
  396. "job": "check_job",
  397. "error": e,
  398. "msg": error_msg
  399. }
  400. )
  401. return
  402. sub_accounts, server_accounts = get_accounts()
  403. fail_list = []
  404. # account_list = sub_accounts + server_accounts
  405. account_list = sub_accounts
  406. # check and rework if fail
  407. for sub_item in tqdm(account_list):
  408. res = check_single_account(db_client, sub_item)
  409. if not res:
  410. update_single_account(db_client, sub_item)
  411. # check whether success and bot if fails
  412. for sub_item in tqdm(account_list):
  413. res = check_single_account(db_client, sub_item)
  414. if not res:
  415. # 去掉三个不需要查看的字段
  416. sub_item.pop('account_type', None)
  417. sub_item.pop('account_auth', None)
  418. sub_item.pop('account_id', None)
  419. fail_list.append(sub_item)
  420. if fail_list:
  421. try:
  422. bot(
  423. title="日常报警, 存在账号更新失败",
  424. detail={
  425. "columns": generate_bot_columns(),
  426. "rows": fail_list
  427. },
  428. table=True
  429. )
  430. except Exception as e:
  431. print("Timeout Error: {}".format(e))
  432. else:
  433. bot(
  434. title="校验完成通知",
  435. mention=False,
  436. detail={
  437. "msg": "校验任务完成",
  438. "finish_time": datetime.today().__str__()
  439. }
  440. )
  441. def get_articles(db_client):
  442. """
  443. :return:
  444. """
  445. sql = f"""
  446. SELECT ContentUrl, wx_sn
  447. FROM {ARTICLE_TABLE}
  448. WHERE publish_timestamp in {(const.DEFAULT_STATUS, const.REQUEST_FAIL_STATUS)};"""
  449. response = db_client.select(sql)
  450. return response
  451. def update_publish_timestamp(db_client, row):
  452. """
  453. 更新发布时间戳 && minigram 信息
  454. :param db_client:
  455. :param row:
  456. :return:
  457. """
  458. url = row[0]
  459. wx_sn = row[1]
  460. try:
  461. response = WeixinSpider().get_article_text(url)
  462. response_code = response['code']
  463. if response_code == const.ARTICLE_DELETE_CODE:
  464. publish_timestamp_s = const.DELETE_STATUS
  465. root_source_id_list = []
  466. elif response_code == const.ARTICLE_ILLEGAL_CODE:
  467. publish_timestamp_s = const.ILLEGAL_STATUS
  468. root_source_id_list = []
  469. elif response_code == const.ARTICLE_SUCCESS_CODE:
  470. data = response['data']['data']
  471. publish_timestamp_ms = data['publish_timestamp']
  472. publish_timestamp_s = int(publish_timestamp_ms / 1000)
  473. mini_program = data.get('mini_program', [])
  474. if mini_program:
  475. root_source_id_list = [
  476. urllib.parse.parse_qs(
  477. urllib.parse.unquote(i['path'])
  478. )['rootSourceId'][0]
  479. for i in mini_program
  480. ]
  481. else:
  482. root_source_id_list = []
  483. else:
  484. publish_timestamp_s = const.UNKNOWN_STATUS
  485. root_source_id_list = []
  486. except Exception as e:
  487. publish_timestamp_s = const.REQUEST_FAIL_STATUS
  488. root_source_id_list = []
  489. error_msg = traceback.format_exc()
  490. print(e, error_msg)
  491. update_sql = f"""
  492. UPDATE {ARTICLE_TABLE}
  493. SET publish_timestamp = %s, root_source_id_list = %s
  494. WHERE wx_sn = %s;
  495. """
  496. db_client.update(
  497. sql=update_sql,
  498. params=(
  499. publish_timestamp_s,
  500. json.dumps(root_source_id_list, ensure_ascii=False),
  501. wx_sn
  502. ))
  503. if publish_timestamp_s == const.REQUEST_FAIL_STATUS:
  504. return row
  505. else:
  506. return None
  507. def get_article_detail_job():
  508. """
  509. 获取发布文章详情
  510. :return:
  511. """
  512. try:
  513. db_client = PQMySQL()
  514. except Exception as e:
  515. error_msg = traceback.format_exc()
  516. bot(
  517. title="获取文章详情任务连接数据库失败",
  518. detail={
  519. "job": "get_article_detail_job",
  520. "error": e,
  521. "msg": error_msg
  522. }
  523. )
  524. return
  525. article_tuple = get_articles(db_client)
  526. for article in tqdm(article_tuple):
  527. try:
  528. update_publish_timestamp(db_client=db_client, row=article)
  529. except Exception as e:
  530. print(e)
  531. error_msg = traceback.format_exc()
  532. print(error_msg)
  533. # check 一遍存在请求失败-1 && 0 的文章
  534. process_failed_articles = get_articles(db_client)
  535. fail_list = []
  536. if process_failed_articles:
  537. for article in tqdm(process_failed_articles):
  538. try:
  539. res = update_publish_timestamp(db_client=db_client, row=article)
  540. fail_list.append({"wx_sn": res[1], "url": res[0]})
  541. except Exception as e:
  542. print(e)
  543. error_msg = traceback.format_exc()
  544. print(error_msg)
  545. # 通过msgId 来修改publish_timestamp
  546. update_sql = f"""
  547. UPDATE {ARTICLE_TABLE} oav
  548. JOIN (
  549. SELECT appMsgId, MAX(publish_timestamp) AS publish_timestamp
  550. FROM {ARTICLE_TABLE}
  551. WHERE publish_timestamp > %s
  552. GROUP BY appMsgId
  553. ) vv
  554. ON oav.appMsgId = vv.appMsgId
  555. SET oav.publish_timestamp = vv.publish_timestamp
  556. WHERE oav.publish_timestamp <= %s;
  557. """
  558. affected_rows = db_client.update(
  559. sql=update_sql,
  560. params=(0, 0)
  561. )
  562. # 若还是无 publish_timestamp,用update_time当作 publish_timestamp
  563. update_sql_2 = f"""
  564. UPDATE {ARTICLE_TABLE}
  565. SET publish_timestamp = updateTime
  566. WHERE publish_timestamp < %s;
  567. """
  568. db_client.update(
  569. sql=update_sql_2,
  570. params=0
  571. )
  572. if fail_list:
  573. bot(
  574. title="更新文章任务,请求detail失败",
  575. detail=fail_list
  576. )
  577. def whether_title_unsafe(db_client, title):
  578. """
  579. 检查文章标题是否已经存在违规记录
  580. :param db_client:
  581. :param title:
  582. :return:
  583. """
  584. title_md5 = functions.str_to_md5(title)
  585. sql = f"""
  586. SELECT title_md5
  587. FROM article_unsafe_title
  588. WHERE title_md5 = '{title_md5}';
  589. """
  590. res = db_client.select(sql)
  591. if res:
  592. return True
  593. else:
  594. return False
  595. def monitor(run_date):
  596. """
  597. 监控任务, 监测周期为7天,监测文章是否被违规,若监测到违规文章,则进行告警
  598. :return:
  599. """
  600. try:
  601. pq_client = PQMySQL()
  602. lam_client = longArticlesMySQL()
  603. except Exception as e:
  604. error_msg = traceback.format_exc()
  605. bot(
  606. title="监控任务连接数据库失败",
  607. detail={
  608. "job": "monitor",
  609. "error": str(e),
  610. "msg": error_msg
  611. }
  612. )
  613. return
  614. if not run_date:
  615. run_date = datetime.today().strftime("%Y-%m-%d")
  616. monitor_start_timestamp = int(datetime.strptime(run_date, "%Y-%m-%d").timestamp()) - const.MONITOR_PERIOD
  617. select_sql = f"""
  618. SELECT ghId, accountName, title, ContentUrl, wx_sn, from_unixtime(publish_timestamp) AS publish_timestamp
  619. FROM {ARTICLE_TABLE}
  620. WHERE publish_timestamp >= {monitor_start_timestamp};
  621. """
  622. article_list = pq_client.select(select_sql)
  623. for article in tqdm(article_list, desc="monitor article list"):
  624. gh_id = article[0]
  625. account_name = article[1]
  626. title = article[2]
  627. # 判断标题是否存在违规记录
  628. if whether_title_unsafe(lam_client, title):
  629. continue
  630. url = article[3]
  631. wx_sn = article[4]
  632. publish_date = article[5]
  633. try:
  634. response = spider.get_article_text(url, is_cache=False)
  635. response_code = response['code']
  636. if response_code == const.ARTICLE_ILLEGAL_CODE:
  637. bot(
  638. title="文章违规告警",
  639. detail={
  640. "ghId": gh_id,
  641. "accountName": account_name,
  642. "title": title,
  643. "wx_sn": str(wx_sn),
  644. "publish_date": str(publish_date)
  645. },
  646. mention=False
  647. )
  648. aiditApi.delete_articles(
  649. gh_id=gh_id,
  650. title=title
  651. )
  652. except Exception as e:
  653. error_msg = traceback.format_exc()
  654. log(
  655. task="monitor",
  656. function="monitor",
  657. message="请求文章详情失败",
  658. data={
  659. "ghId": gh_id,
  660. "accountName": account_name,
  661. "title": title,
  662. "wx_sn": str(wx_sn),
  663. "error": str(e),
  664. "msg": error_msg
  665. }
  666. )
  667. def main():
  668. """
  669. main
  670. :return:
  671. """
  672. parser = ArgumentParser()
  673. parser.add_argument(
  674. "--run_task",
  675. help="update: update_job, check: check_job, detail: get_article_detail_job, monitor: monitor")
  676. parser.add_argument(
  677. "--run_date",
  678. help="--run_date %Y-%m-%d",
  679. )
  680. args = parser.parse_args()
  681. if args.run_task:
  682. run_task = args.run_task
  683. match run_task:
  684. case "update":
  685. update_job()
  686. case "check":
  687. check_job()
  688. case "detail":
  689. get_article_detail_job()
  690. case "monitor":
  691. if args.run_date:
  692. run_date = args.run_date
  693. else:
  694. run_date = None
  695. monitor(run_date)
  696. case _:
  697. print("No such task, input update: update_job, check: check_job, detail: get_article_detail_job")
  698. else:
  699. update_job()
  700. check_job()
  701. get_article_detail_job()
  702. if __name__ == '__main__':
  703. main()