newmediamonitoring/monitor/views.py

786 lines
44 KiB
Python

import csv
import datetime
import json
from collections import Counter
import jieba
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.db.models import Sum
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from datetime import timedelta
# Create your views here.
from dashboard.models import Weixin, Weixin_data, Toutiao_data, Weibo_data, Qita_jc, Group, Toutiao, Weibo, Qita, \
Douyin, Douyin_data, News, TimelinessMonitoring, Organization, Wrongly
from monitor.models import Test
def new_media_public_opinion_weixin(request):
weixin = Weixin.objects.all()
group = Group.objects.all()
weixin_data = Weixin_data.objects.all().order_by('-comment')
res = []
for w in weixin_data:
o = dict()
o['id'] = str(w.id)
o['code'] = w.weixin.code
o['title'] = w.title
o['comment'] = w.comment
o['reply'] = w.reply
o['year'] = w.year
o['month'] = w.month
o['day'] = w.day
res.append(o)
return render(request, 'monitor/new-media-public-opinion-weixin.html',
{'res': res, 'weixin': weixin, 'group': group})
def new_media_public_opinion_toutiao(request):
toutiao = Toutiao.objects.all()
group = Group.objects.all()
toutiao_data = Toutiao_data.objects.all().order_by('-count')
res = []
for t in toutiao_data:
o = dict()
o['id'] = str(t.id)
o['code'] = t.toutiao.code
o['image'] = t.toutiao.image
o['title'] = t.title
o['count'] = t.count
o['commentcount'] = t.commentcount
o['reply'] = t.reply
o['year'] = t.year
o['month'] = t.month
o['day'] = t.day
res.append(o)
return render(request, 'monitor/new-media-public-opinion-toutiao.html',
{'res': res, 'toutiao': toutiao, 'group': group})
def new_media_public_opinion_douyin(request):
douyin = Douyin.objects.all()
group = Group.objects.all()
douyin_data = Douyin_data.objects.all().order_by('-comment')
res = []
for d in douyin_data:
o = dict()
o['id'] = str(d.id)
o['code'] = d.newmedia.code
o['image'] = d.newmedia.image
o['count'] = d.count
o['count_jc'] = d.count_jc
o['comment'] = d.comment
o['reply'] = d.reply
o['date'] = d.date
res.append(o)
return render(request, 'monitor/new-media-public-opinion-douyin.html',
{'res': res, 'douyin': douyin, 'group': group})
def new_media_public_opinion_weibo(request):
weibo = Weibo.objects.all()
group = Group.objects.all()
weibo_data = Weibo_data.objects.all().order_by('-like')
res = []
for w in weibo_data:
o = dict()
o['id'] = str(w.id)
o['code'] = w.weibo.code
o['image'] = w.weibo.image
o['title'] = w.title
o['like'] = w.like
o['transpond'] = w.transpond
o['comment'] = w.comment
o['year'] = w.year
o['month'] = w.month
o['day'] = w.day
res.append(o)
return render(request, 'monitor/new-media-public-opinion-weibo.html', {'res': res, 'weibo': weibo, 'group': group})
def new_media_public_opinion_qita(request):
qita = Qita.objects.all()
group = Group.objects.all()
qita_jc = Qita_jc.objects.all().order_by('-comment')
res = []
for q in qita_jc:
o = dict()
o['id'] = str(q.id)
o['type'] = q.qita.type
o['name'] = q.qita.name
o['image'] = q.qita.image
o['count'] = q.count
o['count_jc'] = q.count_jc
o['comment'] = q.comment
o['reply'] = q.reply
o['year'] = q.year
o['month'] = q.month
o['day'] = q.day
res.append(o)
return render(request, 'monitor/new-media-public-opinion-qita.html', {'res': res, 'qita': qita, 'group': group})
def timeliness_monitoring_weixin(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='微信').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-weixin.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
def timeliness_monitoring_weibo(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='微博').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-weibo.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
def timeliness_monitoring_toutiao(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='今日头条').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-toutiao.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
def timeliness_monitoring_douyin(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type__contains='抖音').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-douyin.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
def timeliness_monitoring_qita(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).order_by(
'n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-qita.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
def error_monitoring(request):
wrongly = Wrongly.objects.all()
paginator = Paginator(wrongly, 8)
page = int(request.GET.get('page', 1))
try:
wrongly = paginator.page(page)
except PageNotAnInteger:
wrongly = paginator.page(1)
except EmptyPage:
wrongly = paginator.page(paginator.num_pages)
return render(request, 'monitor/error-monitoring.html',{'wrongly':wrongly})
def sensitive_word_monitoring(request):
data = range(1,8)
return render(request, 'monitor/sensitive-word-monitoring.html',{'data':data})
def comment_on_interactive_monitoring(request):
return render(request, 'monitor/comment-on-interactive-monitoring.html')
def comment_on_interactive_monitoring_json(request):
data = Test.objects.all()[:100]
r = []
for d in data:
content = d.content
r.append(content)
# result = jieba.analyse.textrank(content, topK=400, withWeight=True)
seg_list = jieba.cut(str(r)) # 对文本进行分词
c = Counter()
for x in seg_list: # 进行词频统计
if len(x) > 1 and x != '\r\n':
c[x] += 1
res = []
for (k, v) in c.most_common(200): # 遍历输出高频词
# print('%s%s %s %d' % (' ' * (5 - len(k)), k, '*', v))
# 剔除不是汉字的值
if all(map(lambda c: '\u4e00' <= c <= '\u9fa5', k)):
o = dict()
o['name'] = k
o['value'] = v
res.append(o)
return HttpResponse(json.dumps({
"res": res
}))
def monitoring_report(request):
news = News.objects.filter(type='3').order_by('-date')
count = News.objects.filter(type='3').count()
return render(request, 'monitor/monitoring-report.html', {'news': news, 'count': count})
def monitoring_report_json(request):
news = News.objects.filter(type='3').order_by('date')
# year_now = datetime.datetime.now().year
# year = range(2019, int(year_now) + 1)
# month = range(1, 13)
news_list = []
for n in news:
o = dict()
# o['date'] = n.date
o['count'] = 1
o['year'] = str(n.date).split('-')[0]
o['month'] = str(n.date).split('-')[1]
news_list.append(o)
return JsonResponse(news_list,safe=False)
def test(request):
return render(request, 'monitor/test.html')
def test_json(request):
res = []
with open('D:/2020/舆论监测平台/新媒体监测数据/平凉/Result_PL.csv', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
results = []
try:
for r in reader:
print(r[0])
results.append(r[5])
except:
print("777777777777777777777777777777777777777777777777")
seg_list = jieba.cut(str(results)) # 对文本进行分词
c = Counter()
for x in seg_list: # 进行词频统计
if len(x) > 1 and x != '\r\n':
c[x] += 1
for (k, v) in c.most_common(200): # 遍历输出高频词
if all(map(lambda c: '\u4e00' <= c <= '\u9fa5', k)):
o = dict()
o['name'] = k
o['value'] = v
res.append(o)
return HttpResponse(json.dumps({
"res": res
}))
def timeliness_monitoring_json(request):
timelinessmonitoring_lanzhou_weixin = \
TimelinessMonitoring.objects.filter(city='兰州市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_lanzhou_weibo = \
TimelinessMonitoring.objects.filter(city='兰州市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_lanzhou_toutiao = \
TimelinessMonitoring.objects.filter(city='兰州市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_lanzhou_douyin = \
TimelinessMonitoring.objects.filter(city='兰州市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_lanzhou_qita = \
TimelinessMonitoring.objects.filter(city='兰州市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_jiayuguan_weixin = \
TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiayuguan_weibo = \
TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiayuguan_toutiao = \
TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiayuguan_douyin = \
TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiayuguan_qita = \
TimelinessMonitoring.objects.filter(city__contains='嘉峪关').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_jinchang_weixin = \
TimelinessMonitoring.objects.filter(city='金昌市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jinchang_weibo = \
TimelinessMonitoring.objects.filter(city='金昌市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jinchang_toutiao = \
TimelinessMonitoring.objects.filter(city='金昌市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jinchang_douyin = \
TimelinessMonitoring.objects.filter(city='金昌市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jinchang_qita = \
TimelinessMonitoring.objects.filter(city='金昌市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_jiuquan_weixin = \
TimelinessMonitoring.objects.filter(city='酒泉市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiuquan_weibo = \
TimelinessMonitoring.objects.filter(city='酒泉市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiuquan_toutiao = \
TimelinessMonitoring.objects.filter(city='酒泉市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiuquan_douyin = \
TimelinessMonitoring.objects.filter(city='酒泉市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_jiuquan_qita = \
TimelinessMonitoring.objects.filter(city='酒泉市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_zhangye_weixin = \
TimelinessMonitoring.objects.filter(city='张掖市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_zhangye_weibo = \
TimelinessMonitoring.objects.filter(city='张掖市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_zhangye_toutiao = \
TimelinessMonitoring.objects.filter(city='张掖市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_zhangye_douyin = \
TimelinessMonitoring.objects.filter(city='张掖市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_zhangye_qita = \
TimelinessMonitoring.objects.filter(city='张掖市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_wuwei_weixin = \
TimelinessMonitoring.objects.filter(city='武威市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_wuwei_weibo = \
TimelinessMonitoring.objects.filter(city='武威市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_wuwei_toutiao = \
TimelinessMonitoring.objects.filter(city='武威市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_wuwei_douyin = \
TimelinessMonitoring.objects.filter(city='武威市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_wuwei_qita = \
TimelinessMonitoring.objects.filter(city='武威市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_baiyin_weixin = \
TimelinessMonitoring.objects.filter(city='白银市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_baiyin_weibo = \
TimelinessMonitoring.objects.filter(city='白银市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_baiyin_toutiao = \
TimelinessMonitoring.objects.filter(city='白银市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_baiyin_douyin = \
TimelinessMonitoring.objects.filter(city='白银市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_baiyin_qita = \
TimelinessMonitoring.objects.filter(city='白银市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_tianshui_weixin = \
TimelinessMonitoring.objects.filter(city='天水市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_tianshui_weibo = \
TimelinessMonitoring.objects.filter(city='天水市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_tianshui_toutiao = \
TimelinessMonitoring.objects.filter(city='天水市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_tianshui_douyin = \
TimelinessMonitoring.objects.filter(city='天水市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_tianshui_qita = \
TimelinessMonitoring.objects.filter(city='天水市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_pingliang_weixin = \
TimelinessMonitoring.objects.filter(city='平凉市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_pingliang_weibo = \
TimelinessMonitoring.objects.filter(city='平凉市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_pingliang_toutiao = \
TimelinessMonitoring.objects.filter(city='平凉市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_pingliang_douyin = \
TimelinessMonitoring.objects.filter(city='平凉市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_pingliang_qita = \
TimelinessMonitoring.objects.filter(city='平凉市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_qingyang_weixin = \
TimelinessMonitoring.objects.filter(city='庆阳市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_qingyang_weibo = \
TimelinessMonitoring.objects.filter(city='庆阳市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_qingyang_toutiao = \
TimelinessMonitoring.objects.filter(city='庆阳市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_qingyang_douyin = \
TimelinessMonitoring.objects.filter(city='庆阳市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_qingyang_qita = \
TimelinessMonitoring.objects.filter(city='庆阳市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_dingxi_weixin = \
TimelinessMonitoring.objects.filter(city='定西市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_dingxi_weibo = \
TimelinessMonitoring.objects.filter(city='定西市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_dingxi_toutiao = \
TimelinessMonitoring.objects.filter(city='定西市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_dingxi_douyin = \
TimelinessMonitoring.objects.filter(city='定西市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_dingxi_qita = \
TimelinessMonitoring.objects.filter(city='定西市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_longnan_weixin = \
TimelinessMonitoring.objects.filter(city='陇南市', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_longnan_weibo = \
TimelinessMonitoring.objects.filter(city='陇南市', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_longnan_toutiao = \
TimelinessMonitoring.objects.filter(city='陇南市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_longnan_douyin = \
TimelinessMonitoring.objects.filter(city='陇南市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_longnan_qita = \
TimelinessMonitoring.objects.filter(city='陇南市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_gannan_weixin = \
TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_gannan_weibo = \
TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_gannan_toutiao = \
TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_gannan_douyin = \
TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_gannan_qita = \
TimelinessMonitoring.objects.filter(city__contains='甘南').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
timelinessmonitoring_linxia_weixin = \
TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_linxia_weibo = \
TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_linxia_toutiao = \
TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_linxia_douyin = \
TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_linxia_qita = \
TimelinessMonitoring.objects.filter(city__contains='临夏').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
weixin = [timelinessmonitoring_lanzhou_weixin,timelinessmonitoring_jiayuguan_weixin,timelinessmonitoring_jinchang_weixin,timelinessmonitoring_jiuquan_weixin,timelinessmonitoring_zhangye_weixin,timelinessmonitoring_wuwei_weixin,timelinessmonitoring_baiyin_weixin,timelinessmonitoring_tianshui_weixin,timelinessmonitoring_pingliang_weixin,timelinessmonitoring_qingyang_weixin,timelinessmonitoring_dingxi_weixin,timelinessmonitoring_longnan_weixin,timelinessmonitoring_gannan_weixin,timelinessmonitoring_linxia_weixin]
weibo = [timelinessmonitoring_lanzhou_weibo,timelinessmonitoring_jiayuguan_weibo,timelinessmonitoring_jinchang_weibo,timelinessmonitoring_jiuquan_weibo,timelinessmonitoring_zhangye_weibo,timelinessmonitoring_wuwei_weibo,timelinessmonitoring_baiyin_weibo,timelinessmonitoring_tianshui_weibo,timelinessmonitoring_pingliang_weibo,timelinessmonitoring_qingyang_weibo,timelinessmonitoring_dingxi_weibo,timelinessmonitoring_longnan_weibo,timelinessmonitoring_gannan_weibo,timelinessmonitoring_linxia_weibo]
toutiao = [timelinessmonitoring_lanzhou_toutiao,timelinessmonitoring_jiayuguan_toutiao,timelinessmonitoring_jinchang_toutiao,timelinessmonitoring_jiuquan_toutiao,timelinessmonitoring_zhangye_toutiao,timelinessmonitoring_wuwei_toutiao,timelinessmonitoring_baiyin_toutiao,timelinessmonitoring_tianshui_toutiao,timelinessmonitoring_pingliang_toutiao,timelinessmonitoring_qingyang_toutiao,timelinessmonitoring_dingxi_toutiao,timelinessmonitoring_longnan_toutiao,timelinessmonitoring_gannan_toutiao,timelinessmonitoring_linxia_toutiao]
douyin = [timelinessmonitoring_lanzhou_douyin,timelinessmonitoring_jiayuguan_douyin,timelinessmonitoring_jinchang_douyin,timelinessmonitoring_jiuquan_douyin,timelinessmonitoring_zhangye_douyin,timelinessmonitoring_wuwei_douyin,timelinessmonitoring_baiyin_douyin,timelinessmonitoring_tianshui_douyin,timelinessmonitoring_pingliang_douyin,timelinessmonitoring_qingyang_douyin,timelinessmonitoring_dingxi_douyin,timelinessmonitoring_longnan_douyin,timelinessmonitoring_gannan_douyin,timelinessmonitoring_linxia_douyin]
qita = [timelinessmonitoring_lanzhou_qita,timelinessmonitoring_jiayuguan_qita,timelinessmonitoring_jinchang_qita,timelinessmonitoring_jiuquan_qita,timelinessmonitoring_zhangye_qita,timelinessmonitoring_wuwei_qita,timelinessmonitoring_baiyin_qita,timelinessmonitoring_tianshui_qita,timelinessmonitoring_pingliang_qita,timelinessmonitoring_qingyang_qita,timelinessmonitoring_dingxi_qita,timelinessmonitoring_longnan_qita,timelinessmonitoring_gannan_qita,timelinessmonitoring_linxia_qita]
print(weixin)
print(weibo)
print(toutiao)
print(douyin)
print(qita)
return HttpResponse(json.dumps({
"status":"1",
"weixin":weixin,
"weibo":weibo,
"toutiao":toutiao,
"douyin":douyin,
"qita":qita
}))