From 629f8b9f9b5fc33ac8ea74133390629006594b61 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sun, 16 Oct 2022 18:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=AE=9E=E7=8E=B0=E6=B8=85?= =?UTF-8?q?=E7=90=86=E4=B8=80=E6=8A=93=E5=8F=96=E7=9A=84=E4=BF=83=E9=94=80?= =?UTF-8?q?=E7=A7=8D=E5=AD=90=EF=BC=8C=E5=88=A0=E9=99=A4=E4=BF=83=E9=94=80?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9F=AD=E4=BA=8E=E4=B8=80=E5=A4=A9=E7=9A=84?= =?UTF-8?q?=E5=92=8C=E8=BF=87=E6=9C=9F=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/views.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pt_site/views.py b/pt_site/views.py index 06a5ea2..59a8b25 100644 --- a/pt_site/views.py +++ b/pt_site/views.py @@ -81,7 +81,7 @@ def auto_get_status(): ) logger.info('组装Message:{}'.format(message)) message_list += ( - '> ' + my_site.site.name + ' 信息更新成功!' + message + ' \n\n') + '> ' + my_site.site.name + ' 信息更新成功!' + message + ' \n\n') # pt_spider.send_text(my_site.site.name + ' 信息更新成功!' + message) logger.info(my_site.site.name + '信息更新成功!' + message) else: @@ -151,29 +151,48 @@ def auto_remove_expire_torrents(): 删除过期种子 """ start = time.time() - torrent_info_list = TorrentInfo.objects.all().filter(downloader__isnull=False) + torrent_info_list = TorrentInfo.objects.all() + count = 0 for torrent_info in torrent_info_list: + logger.info('种子名称:{}'.format(torrent_info.name)) expire_time = torrent_info.sale_expire if '无限期' in expire_time: # ToDo 先更新种子信息,然后再判断 continue if expire_time.endswith(':'): expire_time += '00' + torrent_info.sale_expire = expire_time + torrent_info.save() time_now = datetime.datetime.now() - expire_time_parse = datetime.datetime.strptime(expire_time, '%Y-%m-%d %H:%M:%S') - - if time_now >= expire_time_parse: - if not torrent_info.downloader: + try: + expire_time_parse = datetime.datetime.strptime(expire_time, '%Y-%m-%d %H:%M:%S') + logger.info('优惠到期时间:{}'.format(expire_time)) + except Exception as e: + logger.info('优惠到期时间解析错误:{}'.format(e)) + torrent_info.delete() + count += 1 + continue + if (expire_time_parse - time_now).days <= 0: + logger.info('优惠已到期时间:{}'.format(expire_time)) + if torrent_info.downloader: # 未推送到下载器,跳过或删除? - continue + pass if pt_spider.get_torrent_info_from_downloader(torrent_info).code == StatusCodeEnum.OK.code: # todo 设定任务规则: # 免费到期后,下载完毕的种子是删除还是保留? # 未下载完成的,是暂停还是删除? - torrent_info.delete() + pass + count += 1 + torrent_info.delete() end = time.time() pt_spider.send_text( - '> {} 任务运行成功!耗时:{}{} \n'.format('签到', end - start, time.strftime("%Y-%m-%d %H:%M:%S"))) + '> {} 任务运行成功!共清除过期种子{}个,耗时:{}{} \n'.format( + '清除种子', + count, + end - start, + time.strftime("%Y-%m-%d %H:%M:%S") + ) + ) def auto_push_to_downloader():