This commit is contained in:
guange 2019-01-22 14:57:15 +08:00
parent f1528326be
commit 4e57d509de
4 changed files with 31 additions and 19 deletions

View File

@ -18,3 +18,10 @@ def crawl_info(request):
def platform_info(request):
_info = get_platform_info()
return _render_json(_info)
def news(request):
news = News.objects.order_by('-id').all()[0:20]
data = serialize('json', news)
response = HttpResponse(json.dumps(data, ensure_ascii=False),
content_type="application/json; charset=utf-8")
return response

View File

@ -8,28 +8,32 @@ $(function(){
//更新抓取信息
setInterval(function(){
$.ajax('/myapp/api/news.json').done(function(datas){
for(var i in datas){
var data = datas[i];
console.log(i);
}
});
$.ajax('/myapp/api/crawl_info.json').done(function(data){
console.log(data);
$('#crawl_info_total_count').html(data.total_count);
$('#crawl_info_today_count').html(data.today_total_count);
$('#crawl_info_product_count').html(data.product_count);
$('#crawl_info_today_product_count').html(data.today_product_count);
$('#crawl_info_comment_count').html(data.comment_count);
$('#crawl_info_today_comment_count').html(data.today_comment_count);
});
$.ajax('/myapp/api/platform_info.json').done(function(data){
$('#disk_freed').html(data.disk_freed+'G');
$('#disk_used').html(data.disk_used+'G');
$('#mem_free').html(to_g(data.mem_total-data.mem_used)+'G');
$('#mem_used').html(to_g(data.mem_used)+'G');
$('#tasks_count').html(data.tasks);
});
$.ajax('/myapp/api/crawl_info.json').done(function(data){
console.log(data);
$('#crawl_info_total_count').html(data.total_count);
$('#crawl_info_today_count').html(data.today_total_count);
$('#crawl_info_product_count').html(data.product_count);
$('#crawl_info_today_product_count').html(data.today_product_count);
$('#crawl_info_comment_count').html(data.comment_count);
$('#crawl_info_today_comment_count').html(data.today_comment_count);
});
$.ajax('/myapp/api/platform_info.json').done(function(data){
$('#disk_freed').html(data.disk_freed+'G');
$('#disk_used').html(data.disk_used+'G');
$('#mem_free').html(to_g(data.mem_total-data.mem_used)+'G');
$('#mem_used').html(to_g(data.mem_used)+'G');
$('#tasks_count').html(data.tasks);
});
}, 1500);
init();
init2();
$("#el-dialog").addClass("hide");

View File

@ -149,7 +149,7 @@
</thead>
<tbody>
{% for new in news %}
<tr><td style="padding: 0px 11px;box-sizing: border-box;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{{new.comment_id}}</td><td>{{new.content}}</td><td>{{new.comment_time}}</td></tr>
<tr id="tr_news_{{forloop.counter0}}"><td style="padding: 0px 11px;box-sizing: border-box;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" class="news_comment_id">{{new.comment_id}}</td><td class="news_content">{{new.content}}</td><td class="news_comment_time">{{new.comment_time}}</td></tr>
{% endfor %}
</tbody>
</table>

View File

@ -9,5 +9,6 @@ urlpatterns = [
path('result', views.result, name='result'),
path('api/crawl_info.json', apis.crawl_info),
path('api/platform_info.json', apis.platform_info),
path('api/news.json', apis.news),
]