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.
pixiv/PixivSearch/view.py

120 lines
4.3 KiB

6 years ago
# coding=utf-8
import _thread
import json
import os
from django.http import Http404, StreamingHttpResponse, HttpResponse
from django.shortcuts import render
import root
from PixivSearch.dao.bangumi import get_, stop_, getIds
6 years ago
from PixivSearch.migu import GetVideoUrl
from PixivSearch.pac import CreatePacFile
6 years ago
from PixivSearch.pixiv.pixiv import get_nodes
from PixivSearch.settings import logger
6 years ago
from PixivSearch.pac import RuleManage
6 years ago
def search(request):
word = 'R-18'
pageSize = 10
order = 10
type = 'text'
6 years ago
if request.POST.get('word') is not None and len(request.POST.get('word')) > 0:
6 years ago
word = request.POST.get('word')
5 years ago
if request.POST.get('pageSize') is not None and len(request.POST.get('pageSize')) > 0:
6 years ago
pageSize = int(request.POST.get('pageSize'))
5 years ago
if request.POST.get('order') is not None and len(request.POST.get('order')) > 0:
6 years ago
order = int(request.POST.get('order'))
6 years ago
if request.POST.get('type') is not None and len(request.POST.get('type')) > 0:
6 years ago
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': '没有返回结果'}
6 years ago
return render(request, 'pixiv/index.html', nodes)
6 years ago
except ValueError:
raise Http404()
6 years ago
6 years ago
def migu(request):
6 years ago
if request.GET.get('playurl') != '' and request.GET.get('playurl') is not None:
result = GetVideoUrl.getUrl(request.GET.get('playurl'))
6 years ago
else:
6 years ago
result = {'error': '参数不能为空'}
return HttpResponse(json.dumps(result, ensure_ascii=False), content_type='application/json', charset='utf-8')
def pac(request):
action = request.GET.get('action')
value = request.GET.get('value')
if action == 'create':
return HttpResponse(CreatePacFile.create(), content_type='application/x-ns-proxy-autoconfig', charset='utf-8')
else:
if action == 'insert' and value != None and len(value) > 0:
RuleManage.insert(value)
elif action == 'select' and value != None and len(value) > 0:
5 years ago
return render(request, 'pac/list.html', {'rules': RuleManage.select(value)})
6 years ago
elif action == 'delete' and value != None and len(value) > 0:
RuleManage.delete(value)
5 years ago
return render(request, 'pac/list.html', {'rules': RuleManage.select()})
6 years ago
6 years ago
def index(request):
5 years ago
return render(request, 'pixiv/index.html', {'tip': '输入参数进行搜索', 'word': 'R-18', 'pageSize': '10', 'order': '10'})
6 years ago
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 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")
5 years ago
def page_not_found(request,exception):
return render(request, '404.html')
def page_permission_denied(request,exception):
return render(request, '403.html')
def page_inter_error(request):
return render(request, '500.html')