mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
升级 修改ptools.yaml为ptools.toml,并添加自动转换功能
This commit is contained in:
@@ -1099,17 +1099,11 @@ def get_site_torrents(request):
|
||||
|
||||
def get_config_api(request):
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.toml')
|
||||
yaml_file_path = os.path.join(BASE_DIR, 'db/ptools.yaml')
|
||||
if not os.path.exists(file_path):
|
||||
data = ''
|
||||
if os.path.exists(yaml_file_path):
|
||||
with open('db/ptools.yaml', 'r') as yaml_file:
|
||||
data = yaml.load(yaml_file, Loader=yaml.FullLoader)
|
||||
logger.info(f'原始文档{data}')
|
||||
with open(file_path, 'w') as toml_f:
|
||||
toml_f.write('')
|
||||
toml.dump(data, toml_f)
|
||||
logger.info(f'配置文件生成成功!')
|
||||
res = pt_spider.generate_config_file()
|
||||
if res.code != 0:
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg=res.msg
|
||||
).to_dict(), safe=False)
|
||||
try:
|
||||
with open(file_path, 'rb') as f:
|
||||
response = HttpResponse(f)
|
||||
@@ -1118,7 +1112,6 @@ def get_config_api(request):
|
||||
data=response.content.decode('utf8')
|
||||
).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
raise
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='获取配置文件信息失败!'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import contextlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import ssl
|
||||
@@ -16,6 +17,7 @@ import dateutil.parser
|
||||
import opencc
|
||||
import qbittorrentapi
|
||||
import requests
|
||||
import toml
|
||||
import transmission_rpc
|
||||
import urllib3.util.ssl_
|
||||
import yaml
|
||||
@@ -30,6 +32,7 @@ from wxpusher import WxPusher
|
||||
from auto_pt.models import Notify, OCR
|
||||
from pt_site.models import MySite, SignIn, TorrentInfo, SiteStatus, Site
|
||||
from ptools.base import TorrentBaseInfo, PushConfig, CommonResponse, StatusCodeEnum, DownloaderCategory
|
||||
from ptools.settings import BASE_DIR
|
||||
|
||||
urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'
|
||||
|
||||
@@ -2282,3 +2285,29 @@ class PtSpider:
|
||||
msg=message,
|
||||
data=0
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_config_file():
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.toml')
|
||||
yaml_file_path = os.path.join(BASE_DIR, 'db/ptools.yaml')
|
||||
try:
|
||||
if not os.path.exists(file_path):
|
||||
data = ''
|
||||
if os.path.exists(yaml_file_path):
|
||||
with open('db/ptools.yaml', 'r') as yaml_file:
|
||||
data = yaml.load(yaml_file, Loader=yaml.FullLoader)
|
||||
logger.info(f'原始文档{data}')
|
||||
with open(file_path, 'w') as toml_f:
|
||||
toml_f.write('')
|
||||
toml.dump(data, toml_f)
|
||||
logger.info(f'配置文件生成成功!')
|
||||
return CommonResponse.success(
|
||||
msg='配置文件生成成功!',
|
||||
)
|
||||
return CommonResponse.success(
|
||||
msg='配置文件文件已存在!',
|
||||
)
|
||||
except Exception as e:
|
||||
return CommonResponse.success(
|
||||
msg=f'初始化失败!{e}',
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
import requests
|
||||
import toml
|
||||
import yaml
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from django_apscheduler.jobstores import DjangoJobStore
|
||||
@@ -301,10 +302,19 @@ def auto_upgrade():
|
||||
|
||||
def auto_update_license():
|
||||
"""auto_update_license"""
|
||||
with open('db/ptools.yaml', 'r') as f:
|
||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
res = pt_spider.generate_config_file()
|
||||
if res.code != 0:
|
||||
return CommonResponse.error(
|
||||
msg=res.msg
|
||||
)
|
||||
with open('db/ptools.toml', 'r') as f:
|
||||
data = toml.load(f)
|
||||
print(data)
|
||||
pt_helper = data.get('pt_helper')
|
||||
if len(pt_helper) <= 0:
|
||||
return CommonResponse.error(
|
||||
msg='请先配置小助手相关信息再进行操作!'
|
||||
)
|
||||
host = pt_helper.get('host')
|
||||
username = pt_helper.get('username')
|
||||
password = pt_helper.get('password')
|
||||
|
||||
Reference in New Issue
Block a user