master
1029559041@qq.com 6 years ago
parent 7322d7107a
commit f1644c5a3a
  1. 64
      PixivSearch/logging.conf
  2. 282
      PixivSearch/settings.py
  3. 54
      PixivSearch/urls.py
  4. 202
      PixivSearch/view.py
  5. 32
      PixivSearch/wsgi.py
  6. 2
      README.md
  7. 36
      init/packages.txt
  8. 44
      manage.py

@ -1,33 +1,33 @@
[loggers] [loggers]
keys=root,main keys=root,main
[handlers] [handlers]
keys=consoleHandler,fileHandler keys=consoleHandler,fileHandler
[formatters] [formatters]
keys=fmt keys=fmt
[logger_root] [logger_root]
level=DEBUG level=DEBUG
handlers=consoleHandler handlers=consoleHandler
[logger_main] [logger_main]
level=DEBUG level=DEBUG
qualname=file qualname=file
handlers=fileHandler handlers=fileHandler
[handler_consoleHandler] [handler_consoleHandler]
class=StreamHandler class=StreamHandler
level=INFO level=INFO
formatter=fmt formatter=fmt
args=(sys.stdout,) args=(sys.stdout,)
[handler_fileHandler] [handler_fileHandler]
class=FileHandler class=FileHandler
level=DEBUG level=DEBUG
formatter=fmt formatter=fmt
args=('pixiv.log','a','utf-8',False) args=('pixiv.log','a','utf-8',False)
[formatter_fmt] [formatter_fmt]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s:line:%(lineno)d - %(message)s format=%(asctime)s - %(name)s - %(levelname)s - %(module)s:line:%(lineno)d - %(message)s
datefmt=%Y-%m-%d %H:%M:%S datefmt=%Y-%m-%d %H:%M:%S

@ -1,141 +1,141 @@
""" """
Django settings for PixivSearch project. Django settings for PixivSearch project.
Generated by 'django-admin startproject' using Django 1.11.7. Generated by 'django-admin startproject' using Django 1.11.7.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/ https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/ https://docs.djangoproject.com/en/1.11/ref/settings/
""" """
import logging.config import logging.config
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'dh3^+=iugoo*+p_ea4u3dh&b!_zlgs8*m9kc+#*f2eozglsqjh' SECRET_KEY = 'dh3^+=iugoo*+p_ea4u3dh&b!_zlgs8*m9kc+#*f2eozglsqjh'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'PixivSearch.model' 'PixivSearch.model'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ]
ROOT_URLCONF = 'PixivSearch.urls' ROOT_URLCONF = 'PixivSearch.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/')], 'DIRS': [os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'PixivSearch.wsgi.application' WSGI_APPLICATION = 'PixivSearch.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
# DATABASES = { # DATABASES = {
# 'default': { # 'default': {
# 'ENGINE': 'django.db.backends.mysql', # 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'bangumi', # 'NAME': 'bangumi',
# 'USER': 'root', # 'USER': 'root',
# 'PASSWORD': '', # 'PASSWORD': '',
# 'HOST': '184.170.212.72', # 'HOST': '184.170.212.72',
# # 'HOST': 'sukura.top', # # 'HOST': 'sukura.top',
# 'PORT': '3306', # 'PORT': '3306',
# } # }
# } # }
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase', 'NAME': 'mydatabase',
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
}, },
{ {
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
}, },
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ # https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai' TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = False USE_TZ = False
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ # https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/'), os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/'),
] ]
configPath = '%s/logging.conf' % os.path.dirname(__file__).replace('\\', '/') configPath = '%s/logging.conf' % os.path.dirname(__file__).replace('\\', '/')
logging.config.fileConfig(configPath) logging.config.fileConfig(configPath)
logger = logging.getLogger('file') logger = logging.getLogger('file')

@ -1,27 +1,27 @@
"""PixivSearch URL Configuration """PixivSearch URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see: The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/ https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples: Examples:
Function views Function views
1. Add an import: from my_app import views 1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views Class-based views
1. Add an import: from other_app.views import Home 1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url from django.conf.urls import url
from PixivSearch.view import search, index, download, saveConfig, get, start, stop from PixivSearch.view import search, index, download, saveConfig, get, start, stop
urlpatterns = [ urlpatterns = [
url(r'^$', index), url(r'^$', index),
url(r'^pixiv/search', search), url(r'^pixiv/search', search),
url(r'^pixiv/download', download), url(r'^pixiv/download', download),
url(r'^tsdm', saveConfig), url(r'^tsdm', saveConfig),
url(r'^bangumi/get', get), url(r'^bangumi/get', get),
url(r'^bangumi/start', start), url(r'^bangumi/start', start),
url(r'^bangumi/stop', stop) url(r'^bangumi/stop', stop)
] ]

@ -1,101 +1,101 @@
# coding=utf-8 # coding=utf-8
import _thread import _thread
import os import os
import django import django
from django.http import Http404, StreamingHttpResponse, HttpResponse from django.http import Http404, StreamingHttpResponse, HttpResponse
from django.shortcuts import render from django.shortcuts import render
import root import root
from PixivSearch.dao.bangumi import get_, stop_, getIds from PixivSearch.dao.bangumi import get_, stop_, getIds
from PixivSearch.pixiv.pixiv import get_nodes from PixivSearch.pixiv.pixiv import get_nodes
from PixivSearch.settings import logger from PixivSearch.settings import logger
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
django.setup() # 添加的代码 django.setup() # 添加的代码
from PixivSearch.model import config from PixivSearch.model import config
def search(request): def search(request):
word = 'R-18' word = 'R-18'
pageSize = 10 pageSize = 10
order = 10 order = 10
type = 'text' type = 'text'
if request.POST.get('word') != '' and request.POST.get('word') is not None: if request.POST.get('word') != '' and request.POST.get('word') is not None:
word = request.POST.get('word') word = request.POST.get('word')
if request.POST.get('pageSize') != '' and request.POST.get('pageSize') is not None: if request.POST.get('pageSize') != '' and request.POST.get('pageSize') is not None:
pageSize = int(request.POST.get('pageSize')) pageSize = int(request.POST.get('pageSize'))
if request.POST.get('order') != '' and request.POST.get('order') is not None: if request.POST.get('order') != '' and request.POST.get('order') is not None:
order = int(request.POST.get('order')) order = int(request.POST.get('order'))
if request.POST.get('type') != '' and request.POST.get('type') is not None: if request.POST.get('type') != '' and request.POST.get('type') is not None:
type = request.POST.get('type') type = request.POST.get('type')
try: try:
logger.info("word:%s,pageSize:%d,order:%d,type:%s", word, pageSize, order, type) logger.info("word:%s,pageSize:%d,order:%d,type:%s", word, pageSize, order, type)
array = get_nodes([0, word, pageSize, order, type]) array = get_nodes([0, word, pageSize, order, type])
if len(array[0]) > 0: if len(array[0]) > 0:
if request.POST.get('type') == 'img': if request.POST.get('type') == 'img':
nodes = {'imageNodes': array[0], 'msg': array[1], 'download': word + '.zip', 'size': array[2], nodes = {'imageNodes': array[0], 'msg': array[1], 'download': word + '.zip', 'size': array[2],
'word': word, 'pageSize': pageSize, 'order': order, 'type': type, 'word': word, 'pageSize': pageSize, 'order': order, 'type': type,
'imgPath': root.getConfigValue('imgPath'), 'imgPath': root.getConfigValue('imgPath'),
'baseZipPath': root.getConfigValue('baseZipPath')} 'baseZipPath': root.getConfigValue('baseZipPath')}
else: else:
nodes = {'imageNodes': array[0], 'msg': array[1], 'word': word, 'pageSize': pageSize, 'order': order, nodes = {'imageNodes': array[0], 'msg': array[1], 'word': word, 'pageSize': pageSize, 'order': order,
'type': type} 'type': type}
else: else:
nodes = {'tip': '没有返回结果'} nodes = {'tip': '没有返回结果'}
return render(request, 'index.html', nodes) return render(request, 'index.html', nodes)
except ValueError: except ValueError:
raise Http404() raise Http404()
def index(request): def index(request):
return render(request, 'index.html', {'tip': '输入参数进行搜索'}) return render(request, 'index.html', {'tip': '输入参数进行搜索'})
def download(request): def download(request):
# do something... # do something...
def file_iterator(file_name, chunk_size=512): def file_iterator(file_name, chunk_size=512):
with open(file_name) as f: with open(file_name) as f:
while True: while True:
c = f.read(chunk_size) c = f.read(chunk_size)
if c: if c:
yield c yield c
else: else:
break break
fileName = os.path.join(os.path.dirname(__file__), 'static/download/').replace('\\', '/') + request.GET.get( fileName = os.path.join(os.path.dirname(__file__), 'static/download/').replace('\\', '/') + request.GET.get(
'fileName').encode('utf-8') 'fileName').encode('utf-8')
response = StreamingHttpResponse(file_iterator(fileName)) response = StreamingHttpResponse(file_iterator(fileName))
response['Content-Type'] = 'application/octet-stream' response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(request.GET.get('fileName').encode('utf-8')) response['Content-Disposition'] = 'attachment;filename="{0}"'.format(request.GET.get('fileName').encode('utf-8'))
return response return response
def saveConfig(request): def saveConfig(request):
if 'GET' == request.method and request.GET.get('param_name'): if 'GET' == request.method and request.GET.get('param_name'):
p = config.param.objects.get(param_name=request.GET.get('param_name')) p = config.param.objects.get(param_name=request.GET.get('param_name'))
return render(request, 'addConfig.html', p.__dict__) return render(request, 'addConfig.html', p.__dict__)
elif 'POST' == request.method and request.POST.get('param_name') and request.POST.get('param_value'): elif 'POST' == request.method and request.POST.get('param_name') and request.POST.get('param_value'):
p = config.param(param_name=request.POST.get('param_name'), param_value=request.POST.get('param_value')) p = config.param(param_name=request.POST.get('param_name'), param_value=request.POST.get('param_value'))
p.save() p.save()
return render(request, 'addConfig.html', p.__dict__) return render(request, 'addConfig.html', p.__dict__)
else: else:
return render(request, 'addConfig.html') return render(request, 'addConfig.html')
def get(request): def get(request):
return HttpResponse(str(get_().__str__())) return HttpResponse(str(get_().__str__()))
# 测试方法 # 测试方法
def start(request): def start(request):
_thread.start_new_thread(getIds, ()) _thread.start_new_thread(getIds, ())
return HttpResponse("start success") return HttpResponse("start success")
def stop(request): def stop(request):
stop_() stop_()
return HttpResponse("stop success") return HttpResponse("stop success")

@ -1,16 +1,16 @@
""" """
WSGI config for PixivSearch project. WSGI config for PixivSearch project.
It exposes the WSGI callable as a model-level variable named ``application``. It exposes the WSGI callable as a model-level variable named ``application``.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
""" """
import os import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
application = get_wsgi_application() application = get_wsgi_application()

@ -1 +1 @@
# PixivSearch # PixivSearch

@ -1,18 +1,18 @@
aliyun-python-sdk-cloudphoto==1.1.18 aliyun-python-sdk-cloudphoto==1.1.18
aliyun-python-sdk-core-v3==2.8.6 aliyun-python-sdk-core-v3==2.8.6
beautifulsoup4==4.6.0 beautifulsoup4==4.6.0
bs4==0.0.1 bs4==0.0.1
certifi==2018.4.16 certifi==2018.4.16
chardet==3.0.4 chardet==3.0.4
crcmod==1.7 crcmod==1.7
Django==2.0.5 Django==2.0.5
idna==2.6 idna==2.6
lxml==4.2.1 lxml==4.2.1
mysqlclient==1.3.12 mysqlclient==1.3.12
oss2==2.4.0 oss2==2.4.0
param==1.6.1 param==1.6.1
pytz==2018.4 pytz==2018.4
requests==2.18.4 requests==2.18.4
six==1.11.0 six==1.11.0
thrift==0.11.0 thrift==0.11.0
urllib3==1.22 urllib3==1.22

@ -1,22 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError: except ImportError:
# The above import may fail for some other reason. Ensure that the # The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other # issue is really that Django is missing to avoid masking other
# exceptions on Python 2. # exceptions on Python 2.
try: try:
import django import django
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Couldn't import Django. Are you sure it's installed and " "Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you " "available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?" "forget to activate a virtual environment?"
) )
raise raise
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)

Loading…
Cancel
Save