diff --git a/dashboard/models.py b/dashboard/models.py index d60ed6c..b85d96b 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -685,3 +685,72 @@ class CheckCode(models.Model): '手机验证码', max_length=256, null=True, blank=True) phone = models.CharField('电话号', max_length=256, null=True, blank=True) c_time = models.DateTimeField('时间', auto_now_add=True) + + +#新媒体舆情临时表 +class NewmediaSentimentWeixin(models.Model): + id = models.UUIDField('id',primary_key=True,default=uuid.uuid4) + code = models.CharField('公众号',max_length=256,null=True,blank=True) + title = models.CharField('标题',max_length=256,null=True,blank=True) + comment_count = models.CharField('评论数',max_length=256,null=True,blank=True) + reply_count = models.CharField('回复数',max_length=256,null=True,blank=True) + date = models.CharField('发布时间',max_length=256,null=True,blank=True) + + def __str__(self): + return self.title + +class NewmediaSentimentWeibo(models.Model): + id = models.UUIDField('id',primary_key=True,default=uuid.uuid4) + code = models.CharField('微博号',max_length=256,null=True,blank=True) + title = models.CharField('标题',max_length=256,null=True,blank=True) + comment_count = models.CharField('评论数',max_length=256,null=True,blank=True) + reply_count = models.CharField('回复数',max_length=256,null=True,blank=True) + date = models.CharField('发布时间',max_length=256,null=True,blank=True) + + def __str__(self): + return self.title +class NewmediaSentimentToutiao(models.Model): + id = models.UUIDField('id',primary_key=True,default=uuid.uuid4) + code = models.CharField('头条号',max_length=256,null=True,blank=True) + title = models.CharField('标题',max_length=256,null=True,blank=True) + comment_count = models.CharField('评论数',max_length=256,null=True,blank=True) + reply_count = models.CharField('回复数',max_length=256,null=True,blank=True) + date = models.CharField('发布时间',max_length=256,null=True,blank=True) + + def __str__(self): + return self.title +#时效性监测临时表 +class TimelinessMonitoring(models.Model): + id = models.UUIDField('id',primary_key=True,default=uuid.uuid4()) + n_type = models.CharField('新媒体类型',max_length=256,null=True,blank=True) + n_name = models.CharField('新媒体名称',max_length=256,null=True,blank=True) + o_type = models.CharField('主体类型',max_length=256,null=True,blank=True) + o_name = models.CharField('主体名称',max_length=256,null=True,blank=True) + city = models.CharField('市',null=True,blank=True,max_length=256) + counties = models.CharField('县区',max_length=256,null=True,blank=True) + remark = models.CharField('备注',max_length=256,null=True,blank=True) + results = models.CharField('监测结果',max_length=256,null=True,blank=True) + update = models.IntegerField('更新次数',max_length=256,null=True,blank=True) + silet = models.IntegerField('最大连续静默日数',max_length=256,null= True,blank=True) + start_data = models.CharField('开始时间',max_length=256,null=True,blank=True) + end_data = models.CharField('结束时间',max_length=256,null=True,blank=True) + comment = models.IntegerField('评论次数',max_length=256,null=True,blank=True) + date = models.CharField('最近更新时间',max_length=256,null=True,blank=True) + + def __str__(self): + return self.n_name + +#错别字临时表 +class Wrongly(models.Model): + id = models.UUIDField('id',primary_key=True,default=uuid.uuid4) + error = models.CharField('错误',max_length=256,null=True,blank=True) + idea = models.CharField('建议',max_length=256,null=True,blank=True) + site = models.TextField('上下文',null=True,blank=True) + n_type = models.CharField('新媒体类型',max_length=256,null=True,blank=True) + n_name = models.CharField('新媒体名称',max_length=256,null=True,blank=True) + date = models.CharField('发布时间',max_length=256,null=True,blank=True) + title = models.CharField('标题',max_length=256,null=True,blank=True) + url = models.CharField('URL',max_length=256,null=True,blank=True) + + def __str__(self): + return self.title diff --git a/dashboard/templates/dashboard/index.html b/dashboard/templates/dashboard/index.html index e9dd389..ddd8808 100644 --- a/dashboard/templates/dashboard/index.html +++ b/dashboard/templates/dashboard/index.html @@ -78,70 +78,82 @@
-
- {# #} - - +
-
- {# #} - - +
-
- {# #} - -
-

{{ toutiao_count }}

- 今日头条 + +
+ {# #} + +
+

{{ toutiao_count }}

+ 今日头条 +
-
+
-
- {# #} - - +
-
- {# #} - -
-

{{ qita_count }}

- 其他新媒体 + +
+ {# #} + +
+

{{ qita_count }}

+ 其他新媒体 +
-
+
-
- {# #} - -
-

{{ organization_count }}

- 注册单位 + +
+ {# #} + +
+

{{ organization_count }}

+ 注册单位 +
-
+
diff --git a/import_时效性监测.py b/import_时效性监测.py new file mode 100644 index 0000000..4920141 --- /dev/null +++ b/import_时效性监测.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +import csv +import uuid +import os +import psycopg2 + +from pip._vendor import chardet + +# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214' +G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#' + + +def insert_shixiaoxingjiance(n_type, n_name, o_type, o_name, city, counties, remark, results, update, silet,start, end): + with psycopg2.connect(G2) as connection: + with connection.cursor() as cursor: + id = uuid.uuid4() + cursor.execute( + "insert into dashboard_timelinessmonitoring(id,n_type, n_name, o_type, o_name, city, counties, remark, results, update, silet,start_data,end_data,comment,date) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,null ,null )" + , (str(id), n_type, n_name, o_type, o_name, city, counties, remark, results, update,silet,start,end)) + connection.commit() + + +if __name__ == '__main__': + + with open('D:/2020/舆论监测平台/XMTJC/数据/时效性监测临时表.csv', encoding='utf-8') as csvfile: + reader = csv.reader(csvfile) + for r in reader: + print(r) + n_type = r[0] + n_name = r[1] + o_type = r[2] + o_name = r[3] + city = r[4] + counties = r[5] + remark = r[6] + results = r[7] + update = r[8] + silet = r[9] + start = r[10] + end = r[11] + + insert_shixiaoxingjiance(n_type, n_name, o_type, o_name, city, counties, remark, results, update, silet,start, end) diff --git a/import_错别字.py b/import_错别字.py new file mode 100644 index 0000000..61d3914 --- /dev/null +++ b/import_错别字.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +import csv +import uuid +import os +import psycopg2 + +from pip._vendor import chardet + +# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214' +G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#' + + +def insert_shixiaoxingjiance(error, idea, site, n_type, n_name, date, title): + with psycopg2.connect(G2) as connection: + with connection.cursor() as cursor: + id = uuid.uuid4() + cursor.execute( + "insert into dashboard_wrongly(id,error, idea, site, n_type, n_name, date, title,url) values (%s,%s,%s,%s,%s,%s,%s,%s,null )" + , (str(id),error, idea, site, n_type, n_name, date, title)) + connection.commit() + + +if __name__ == '__main__': + + with open('D:/2020/舆论监测平台/XMTJC/数据/错别字临时表.csv', encoding='utf-8') as csvfile: + reader = csv.reader(csvfile) + for r in reader: + print(r) + error = r[0] + idea = r[1] + site = r[2] + n_type = r[3] + n_name = r[4] + date = r[5] + title = r[6] + + + insert_shixiaoxingjiance(error, idea, site, n_type, n_name, date, title) diff --git a/monitor/templates/monitor/comment-on-interactive-monitoring.html b/monitor/templates/monitor/comment-on-interactive-monitoring.html index fb87d32..1ab8084 100644 --- a/monitor/templates/monitor/comment-on-interactive-monitoring.html +++ b/monitor/templates/monitor/comment-on-interactive-monitoring.html @@ -65,35 +65,35 @@
-
-
-
热点评论
-
- - - - - - - - - - - - - - - - - - - - -
新媒体类型账号名评论内容时间跟评数
{{ r.date }}{{ r.date }}{{ r.date }}{{ r.date }}{{ r.date }}
-
- -
-
+{#
#} +{#
#} +{#
热点评论
#} +{#
#} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{#
新媒体类型账号名评论内容时间跟评数
{{ r.date }}{{ r.date }}{{ r.date }}{{ r.date }}{{ r.date }}
#} +{#
#} +{##} +{#
#} +{#
#}
diff --git a/monitor/templates/monitor/timeliness-monitoring.html b/monitor/templates/monitor/timeliness-monitoring.html index 3c3d6ba..6d477f9 100644 --- a/monitor/templates/monitor/timeliness-monitoring.html +++ b/monitor/templates/monitor/timeliness-monitoring.html @@ -25,15 +25,15 @@

内容更新次数

-

288

+

{{ update_count }}

本周新增次数

本月新增次数

@@ -57,14 +57,14 @@
- -

新媒体数量

+
+

主体数量

288

本周新增

本月新增

diff --git a/monitor/views.py b/monitor/views.py index 9351a02..790490d 100644 --- a/monitor/views.py +++ b/monitor/views.py @@ -1,14 +1,16 @@ import csv +import datetime import json from collections import Counter import jieba +from django.db.models import Sum from django.http import HttpResponse 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 + Douyin, Douyin_data, News, TimelinessMonitoring, Organization, Wrongly from monitor.models import Test @@ -119,7 +121,29 @@ def new_media_public_opinion_qita(request): def timeliness_monitoring(request): - return render(request, 'monitor/timeliness-monitoring.html') + 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().count() + update = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update')) + update_count = update['nums'] + + + comment = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment')) + comment_count = comment['nums'] + wrongly_count = Wrongly.objects.all().count + sensitive_count = None + organization_count = Organization.objects.all().count() + + return render(request, 'monitor/timeliness-monitoring.html',{'new_media_count':new_media_count,'new_media_count_month':new_media_count_month,'new_media_count_week':new_media_count_week,'update_count':update_count,'comment_count':comment_count,'wrongly_count':wrongly_count,'organization_count':organization_count}) def error_monitoring(request):