2019-01-15 19:04:43 +08:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from . import scrapy_client
|
2019-01-18 16:26:18 +08:00
|
|
|
from myapp.models import CrawlInfos,PlatformInfos, News,LastDayCounts, Datas, Top10Sells
|
2019-01-17 20:15:22 +08:00
|
|
|
from myapp.utils import get_platform_info
|
|
|
|
import json
|
2019-01-15 19:04:43 +08:00
|
|
|
|
|
|
|
def index(request):
|
|
|
|
return render(request, 'myapp/index.html')
|
|
|
|
|
|
|
|
def crawl(request):
|
2019-01-18 10:27:30 +08:00
|
|
|
# info = scrapy_client.get_scrapy_info()
|
|
|
|
crawl_info = CrawlInfos.objects.order_by('-id').first()
|
|
|
|
platform_info = get_platform_info()
|
2019-01-18 10:26:32 +08:00
|
|
|
news = News.objects.order_by('-id').all()[0:20]
|
2019-01-18 14:03:00 +08:00
|
|
|
last_day_counts = LastDayCounts.objects.order_by("last_day").all()
|
|
|
|
|
|
|
|
last_day_product = []
|
|
|
|
last_day_comment = []
|
|
|
|
for last_day in last_day_counts:
|
|
|
|
last_day_product.append(last_day.product_c)
|
|
|
|
last_day_comment.append(last_day.comment_c)
|
|
|
|
|
2019-01-18 10:27:30 +08:00
|
|
|
return render(request, 'myapp/crawl.html', {"crawl_info": crawl_info,
|
2019-01-18 10:16:23 +08:00
|
|
|
"platform_info":json.dumps(platform_info),
|
2019-01-18 14:03:00 +08:00
|
|
|
"news": news,
|
|
|
|
"last_day_product":json.dumps(last_day_product),
|
|
|
|
"last_day_comment": json.dumps(last_day_comment)})
|
2019-01-15 19:04:43 +08:00
|
|
|
|
2019-01-17 20:15:22 +08:00
|
|
|
def result(request):
|
2019-01-18 15:28:34 +08:00
|
|
|
from_type_info = json.loads(Datas.objects.filter(key='from_type').first().data)
|
2019-01-18 16:28:47 +08:00
|
|
|
top10_sells = [entry for entry in Top10Sells.objects.order_by('id').values()]
|
2019-01-18 17:30:58 +08:00
|
|
|
|
|
|
|
last_month_sell = json.loads(Datas.objects.filter(key='last_month_sell').first().data)
|
2019-01-18 18:58:51 +08:00
|
|
|
|
|
|
|
hour_sell = json.loads(Datas.objects.filter(key='hour_sell').first().data)
|
2019-01-18 16:26:18 +08:00
|
|
|
return render(request, 'myapp/result.html', {"from_type_info": from_type_info,
|
2019-01-18 18:58:51 +08:00
|
|
|
"top10_sells": top10_sells, "last_month_sell": last_month_sell, "hour_sell": hour_sell})
|