master
10295 7 years ago
parent bad777ad6c
commit bd556a441d
  1. 11
      PixivSearch/dao/bangumi.py
  2. 3
      PixivSearch/urls.py
  3. 6
      PixivSearch/view.py

@ -14,6 +14,7 @@ django.setup()
from PixivSearch.model.config import mediaInfo, stat from PixivSearch.model.config import mediaInfo, stat
current_mediaInfo = mediaInfo(id=0, chn_name='null') current_mediaInfo = mediaInfo(id=0, chn_name='null')
flag = True flag = True
@ -21,6 +22,7 @@ class bangumi(threading.Thread):
begin = 0 begin = 0
end = 0 end = 0
id = 0 id = 0
flag = True
def __init__(self, begin, end): def __init__(self, begin, end):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -47,11 +49,18 @@ class bangumi(threading.Thread):
self.go(self.begin, self.end) self.go(self.begin, self.end)
def get(self): def get(self):
global current_mediaInfo
return current_mediaInfo return current_mediaInfo
def stop(self):
global flag
flag = False
def go(self, start, end): def go(self, start, end):
global flag
flag = True
for num in range(start, end): for num in range(start, end):
if (flag): if flag:
time.sleep(1) time.sleep(1)
logger.info("爬虫进度:%d" % num) logger.info("爬虫进度:%d" % num)
self.id = num self.id = num

@ -14,7 +14,7 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url 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 = [ urlpatterns = [
url(r'^$', index), url(r'^$', index),
@ -24,4 +24,5 @@ urlpatterns = [
url(r'^bangumi/save', save), url(r'^bangumi/save', save),
url(r'^bangumi/get', get), url(r'^bangumi/get', get),
url(r'^bangumi/start', start), url(r'^bangumi/start', start),
url(r'^bangumi/stop', stop)
] ]

@ -89,7 +89,7 @@ def save(request):
def get(request): def get(request):
return HttpResponse(str(bangumi.get(None).__str__())) return HttpResponse(str(bangumi.get(bangumi).__str__()))
def start(request): def start(request):
@ -98,3 +98,7 @@ def start(request):
bangumi(begin=begin, end=end).start() bangumi(begin=begin, end=end).start()
return HttpResponse("start success") return HttpResponse("start success")
def stop(request):
bangumi.stop(bangumi)
return HttpResponse("stop success")
Loading…
Cancel
Save