From bd556a441d62f8de6843d37887519bfcba9d13f5 Mon Sep 17 00:00:00 2001 From: 10295 <1029559041@qq.com> Date: Thu, 22 Mar 2018 03:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PixivSearch/dao/bangumi.py | 11 ++++++++++- PixivSearch/urls.py | 3 ++- PixivSearch/view.py | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/PixivSearch/dao/bangumi.py b/PixivSearch/dao/bangumi.py index 471f1c1..6a3c3eb 100644 --- a/PixivSearch/dao/bangumi.py +++ b/PixivSearch/dao/bangumi.py @@ -14,6 +14,7 @@ django.setup() from PixivSearch.model.config import mediaInfo, stat current_mediaInfo = mediaInfo(id=0, chn_name='null') + flag = True @@ -21,6 +22,7 @@ class bangumi(threading.Thread): begin = 0 end = 0 id = 0 + flag = True def __init__(self, begin, end): threading.Thread.__init__(self) @@ -47,11 +49,18 @@ class bangumi(threading.Thread): self.go(self.begin, self.end) def get(self): + global current_mediaInfo return current_mediaInfo + def stop(self): + global flag + flag = False + def go(self, start, end): + global flag + flag = True for num in range(start, end): - if (flag): + if flag: time.sleep(1) logger.info("爬虫进度:%d" % num) self.id = num diff --git a/PixivSearch/urls.py b/PixivSearch/urls.py index 5808d3f..0b174fd 100644 --- a/PixivSearch/urls.py +++ b/PixivSearch/urls.py @@ -14,7 +14,7 @@ Including another URLconf 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, save, get, start +from PixivSearch.view import search, index, download, saveConfig, save, get, start, stop urlpatterns = [ url(r'^$', index), @@ -24,4 +24,5 @@ urlpatterns = [ url(r'^bangumi/save', save), url(r'^bangumi/get', get), url(r'^bangumi/start', start), + url(r'^bangumi/stop', stop) ] diff --git a/PixivSearch/view.py b/PixivSearch/view.py index b89f988..b2baba1 100644 --- a/PixivSearch/view.py +++ b/PixivSearch/view.py @@ -89,7 +89,7 @@ def save(request): def get(request): - return HttpResponse(str(bangumi.get(None).__str__())) + return HttpResponse(str(bangumi.get(bangumi).__str__())) def start(request): @@ -98,3 +98,7 @@ def start(request): bangumi(begin=begin, end=end).start() return HttpResponse("start success") + +def stop(request): + bangumi.stop(bangumi) + return HttpResponse("stop success") \ No newline at end of file