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

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

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

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

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

@ -1 +1 @@
# PixivSearch
# PixivSearch

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

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

Loading…
Cancel
Save