parent
2f1006d2ff
commit
2dec6bc0a5
@ -0,0 +1,61 @@ |
||||
import json |
||||
import re |
||||
|
||||
import requests |
||||
from bs4 import BeautifulSoup |
||||
|
||||
|
||||
def getUrl(playurl): |
||||
# 请求头 |
||||
headers = { |
||||
'X-Requested-With': 'XMLHttpRequest', |
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ' |
||||
'Chrome/56.0.2924.87 Safari/537.36' |
||||
} |
||||
|
||||
# headers['referer']='http://www.miguvideo.com/wap/resource/pc/detail/miguplay.jsp?cid=650644142' |
||||
|
||||
baseurl = 'www.miguvideo.com/wap/resource/pc/detail/miguplay.jsp' |
||||
try: |
||||
if re.match("^(http|https):\/\/www\.miguvideo\.com\/wap\/resource\/pc\/detail\/miguplay\.jsp\?cid=\d+$",playurl): |
||||
req = requests.get(playurl, headers=headers) |
||||
sessionID = 0 |
||||
playId = 0 |
||||
# 提取接口参数 |
||||
cid = re.findall('\d+', playurl)[0] |
||||
# 获取sessionID |
||||
result={'msg':'网络异常'} |
||||
if req.status_code == 200: |
||||
document = BeautifulSoup(req.text, 'lxml') |
||||
print('sessionID=%s' % sessionID) |
||||
sessionID = document.select('#sessionID')[0].get('value') |
||||
print('sessionID=%s' % sessionID) |
||||
# 获取playId |
||||
if req.status_code == 200: |
||||
req = requests.get('http://www.miguvideo.com/wap/resource/pc/data/miguData.jsp?cid=%s' % cid, |
||||
headers=headers) |
||||
miguData = json.loads(req.text) |
||||
print('playId=%s' % playId) |
||||
playId = miguData[0]['playId'] |
||||
print('playId=%s' % playId) |
||||
|
||||
# 使用播放地址接口获取视频信息 |
||||
req = requests.get( |
||||
'http://www.miguvideo.com/playurl/v1/play/playurlh5?contId=%s&rateType=1,2,3&clientId=%s' % ( |
||||
playId, sessionID)) |
||||
if req.status_code == 200: |
||||
videoInfo = json.loads(req.text) |
||||
# 解析出json结构视频信息,获取视频真实地址 |
||||
result = {'name': miguData[0]['Detail'],'video':[]}; |
||||
print("视频信息=%s" % miguData[0]['Detail']) |
||||
if videoInfo['code'] == '200' and 'body' in videoInfo and 'urlInfos' in videoInfo['body']: |
||||
for info in videoInfo['body']['urlInfos']: |
||||
result['video'].append({'rateDesc':info['rateDesc'],'url':info['url'],'mediaSize':info['mediaSize']}) |
||||
print('清晰度=%s' % info['rateDesc']) |
||||
print('真实地址=%s' % info['url']) |
||||
print('视频大小=%s字节' % info['mediaSize']) |
||||
else: |
||||
result = {'msg': '不是合法播放地址'} |
||||
except BaseException as e: |
||||
result={'msg':'程序异常'} |
||||
return result |
@ -1,141 +1,163 @@ |
||||
""" |
||||
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', |
||||
'corsheaders' |
||||
] |
||||
|
||||
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', |
||||
'corsheaders.middleware.CorsMiddleware', |
||||
'django.middleware.common.CommonMiddleware' |
||||
] |
||||
#跨域增加忽略 |
||||
CORS_ALLOW_CREDENTIALS = True |
||||
CORS_ORIGIN_ALLOW_ALL = True |
||||
CORS_ORIGIN_WHITELIST = ( '*') |
||||
CORS_ALLOW_METHODS = ( 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'VIEW', ) |
||||
CORS_ALLOW_HEADERS = ( |
||||
'XMLHttpRequest', |
||||
'X_FILENAME', |
||||
'accept-encoding', |
||||
'authorization', |
||||
'content-type', |
||||
'dnt', |
||||
'origin', |
||||
'user-agent', |
||||
'x-csrftoken', |
||||
'x-requested-with', |
||||
'Pragma', |
||||
) |
||||
|
||||
|
||||
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,28 @@ |
||||
"""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, migu |
||||
|
||||
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), |
||||
url(r'^migu',migu) |
||||
] |
||||
|
@ -1,101 +1,108 @@ |
||||
# 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 json |
||||
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 |
||||
from PixivSearch.migu import GetVideoUrl |
||||
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 migu(request): |
||||
if request.GET.get('playurl')!='' and request.GET.get('playurl') is not None: |
||||
result=GetVideoUrl.getUrl(request.GET.get('playurl')) |
||||
else: |
||||
result={'参数不能为空'} |
||||
return HttpResponse(json.dumps(result,ensure_ascii=False), content_type='application/json', charset='utf-8') |
||||
|
||||
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") |
||||
|
Loading…
Reference in new issue