You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.4 KiB
104 lines
3.4 KiB
# coding=utf-8
|
|
import os
|
|
|
|
import django
|
|
from django.http import Http404, StreamingHttpResponse, HttpResponse
|
|
from django.shortcuts import render
|
|
|
|
from PixivSearch.dao.bangumi import bangumi
|
|
from PixivSearch.settings import logger
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
|
|
django.setup() # 添加的代码
|
|
|
|
from PixivSearch.model import config
|
|
from PixivSearch.pixiv import get_nodes
|
|
|
|
|
|
def search(request):
|
|
if request.POST.get('word') != '':
|
|
word = request.POST.get('word')
|
|
else:
|
|
word = 'R-18'
|
|
if request.POST.get('pageSize') != '':
|
|
pageSize = request.POST.get('pageSize')
|
|
else:
|
|
pageSize = 10
|
|
if request.POST.get('order') != '':
|
|
order = request.POST.get('order')
|
|
else:
|
|
order = 10
|
|
if request.POST.get('type') != '':
|
|
type = request.POST.get('type')
|
|
else:
|
|
type = None
|
|
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]}
|
|
else:
|
|
nodes = {'imageNodes': array[0], 'msg': array[1]}
|
|
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 save(request):
|
|
media_id = int(request.GET.get('id'))
|
|
bangumi.save(media_id)
|
|
return HttpResponse("save success")
|
|
|
|
|
|
def get(request):
|
|
return HttpResponse(str(bangumi.get(bangumi).__str__()))
|
|
|
|
|
|
def start(request):
|
|
begin = int(request.GET.get('start'))
|
|
end = int(request.GET.get('end'))
|
|
bangumi(begin=begin, end=end).start()
|
|
|
|
return HttpResponse("start success")
|
|
|
|
def stop(request):
|
|
bangumi.stop(bangumi)
|
|
return HttpResponse("stop success") |