diff --git a/pt_test/__init__.py b/pt_test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pt_test/admin.py b/pt_test/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/pt_test/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/pt_test/apps.py b/pt_test/apps.py new file mode 100644 index 0000000..4887576 --- /dev/null +++ b/pt_test/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PtTestConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "pt_test" diff --git a/pt_test/migrations/__init__.py b/pt_test/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pt_test/models.py b/pt_test/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/pt_test/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/pt_test/tests.py b/pt_test/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/pt_test/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/pt_test/urls.py b/pt_test/urls.py new file mode 100644 index 0000000..67ab04b --- /dev/null +++ b/pt_test/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path(r'test_import', views.test_import, name='test_import'), +] diff --git a/pt_test/views.py b/pt_test/views.py new file mode 100644 index 0000000..d52d63a --- /dev/null +++ b/pt_test/views.py @@ -0,0 +1,48 @@ +# Create your views here. +import json + +from django.http import JsonResponse +from django.shortcuts import render + +from pt_site.views import pt_spider +from ptools.base import CommonResponse, StatusCodeEnum + + +def test_import(request): + if request.method == 'GET': + return render(request, 'pt_test/test_import.html') + else: + data_list = json.loads(request.body).get('user') + res = pt_spider.parse_ptpp_cookies(data_list) + if res.code == StatusCodeEnum.OK.code: + cookies = res.data + print(cookies) + else: + return JsonResponse(res.to_dict(), safe=False) + message_list = [] + for data in cookies: + try: + print(data) + res = pt_spider.get_uid_and_passkey(data) + msg = res.msg + print(msg) + if res.code == StatusCodeEnum.OK.code: + message_list.append({ + 'msg': msg, + 'tag': 'success' + }) + else: + # error_messages.append(msg) + message_list.append({ + 'msg': msg, + 'tag': 'error' + }) + except Exception as e: + message = '{} 站点导入失败!{} \n'.format(data.get('domain'), str(e)) + message_list.append({ + 'msg': message, + 'tag': 'warning' + }) + return JsonResponse(CommonResponse.success(data={ + 'messages': message_list + }).to_dict(), safe=False) diff --git a/ptools/settings.py b/ptools/settings.py index ac06570..431d57d 100644 --- a/ptools/settings.py +++ b/ptools/settings.py @@ -48,6 +48,7 @@ INSTALLED_APPS = [ 'import_export', 'django_apscheduler', 'pt_site', + 'pt_test', 'auto_pt', ] diff --git a/ptools/urls.py b/ptools/urls.py index 5e5f5b9..0c12126 100644 --- a/ptools/urls.py +++ b/ptools/urls.py @@ -28,6 +28,7 @@ urlpatterns = [ path('', index), path(r'admin/', admin.site.urls), path(r'tasks/', include("auto_pt.urls"), name='tasks'), # - path(r'site/', include("pt_site.urls"), name='tasks') # + path(r'site/', include("pt_site.urls"), name='tasks'), # + path(r'test/', include("pt_test.urls"), name='test'), # ] diff --git a/templates/pt_test/test_import.html b/templates/pt_test/test_import.html new file mode 100644 index 0000000..1c844fd --- /dev/null +++ b/templates/pt_test/test_import.html @@ -0,0 +1,293 @@ +{% load static %} + + + +
+ {% include 'admin/includes/css-part.html' %} + + + +