mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
功能优化
This commit is contained in:
@@ -32,6 +32,7 @@ urlpatterns = [
|
||||
path(r'get_log_list', views.get_log_list, name='get_log_list'),
|
||||
path(r'show_log_list', views.show_log_list, name='show_log_list'),
|
||||
path(r'get_log_content', views.get_log_content, name='get_log_content'),
|
||||
path(r'get_helper_license', views.get_helper_license, name='get_helper_license'),
|
||||
path(r'downloading_status', views.downloading_status, name='downloading_status'),
|
||||
path(r'do_sql', views.do_sql, name='do_sql'),
|
||||
]
|
||||
|
||||
@@ -986,3 +986,12 @@ def site_sort_api(request):
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg=f'数据更新失败:{e}'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def get_helper_license(request):
|
||||
result = pt_site.auto_update_license()
|
||||
if result.code == 0:
|
||||
return JsonResponse(data=result.to_dict(), safe=False)
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='License更新失败!'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
@@ -8,8 +8,11 @@ import subprocess
|
||||
import time
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from django_apscheduler.jobstores import DjangoJobStore
|
||||
from lxml import etree
|
||||
|
||||
from pt_site.UtilityTool import PtSpider, MessageTemplate, FileSizeConvert
|
||||
from pt_site.models import MySite, TorrentInfo
|
||||
@@ -296,6 +299,55 @@ 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)
|
||||
print(data)
|
||||
pt_helper = data.get('pt_helper')
|
||||
host = pt_helper.get('host')
|
||||
username = pt_helper.get('username')
|
||||
password = pt_helper.get('password')
|
||||
url = 'http://get_pt_helper_license.guyubao.com/getTrial'
|
||||
license_xpath = '//h2/text()'
|
||||
session = requests.Session()
|
||||
res = session.get(url=url)
|
||||
token = ''.join(etree.HTML(res.content).xpath(license_xpath))
|
||||
login_url = host + '/login/submit'
|
||||
login_res = session.post(
|
||||
url=login_url,
|
||||
data={
|
||||
'username': username,
|
||||
'password': password,
|
||||
}
|
||||
)
|
||||
token_url = host + '/sys/config/update'
|
||||
logger.info(login_res.cookies.get_dict())
|
||||
cookies = session.cookies.get_dict()
|
||||
logger.info(cookies)
|
||||
res = session.post(
|
||||
url=token_url,
|
||||
cookies=cookies,
|
||||
data={
|
||||
'Id': 4,
|
||||
'ParamKey': 'license',
|
||||
'ParamValue': token.split(':')[-1],
|
||||
'Status': 1,
|
||||
}
|
||||
)
|
||||
logger.info(f'结果:{res.text}')
|
||||
result = res.json()
|
||||
if result.get('code') == 0:
|
||||
result['data'] = token
|
||||
pt_spider.send_text(text=f'> {token}')
|
||||
return CommonResponse.success(
|
||||
data=result
|
||||
)
|
||||
return CommonResponse.error(
|
||||
msg=f'License更新失败!'
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind(("127.0.0.1", 44444))
|
||||
|
||||
Reference in New Issue
Block a user