#add message
This commit is contained in:
parent
fd15ae8736
commit
3d3d94640d
|
@ -34,17 +34,22 @@
|
||||||
<!-- Default panel contents -->
|
<!-- Default panel contents -->
|
||||||
<form action="{% url 'backstage-error' %}" method="post"
|
<form action="{% url 'backstage-error' %}" method="post"
|
||||||
enctype="multipart/form-data">{% csrf_token %}
|
enctype="multipart/form-data">{% csrf_token %}
|
||||||
{# <div class="form-group col-md-4">#}
|
<div class="form-group col-md-6">
|
||||||
{# <label for="date">时间</label>#}
|
<label for="city">市</label>
|
||||||
{# <input type="date" class="form-control" id="source"#}
|
<input type="text" class="form-control" id="source"
|
||||||
{# name="date">#}
|
name="city">
|
||||||
{# </div>#}
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group col-md-6">
|
||||||
|
<label for="jc_date">监测时间</label>
|
||||||
|
<input type="date" class="form-control" id="source"
|
||||||
|
name="jc_date">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-12" style="margin-left: 10%">
|
||||||
<label for="exampleInputFile">点击上传文件</label>
|
<label for="exampleInputFile">点击上传文件</label>
|
||||||
<input type="file" id="exampleInputFile" name="file">
|
<input type="file" id="exampleInputFile" name="file">
|
||||||
<p class="help-block">请上传csv文件(文件表头依次为:错误、建议、定位、新媒体类型、账号、发文时间、标题、市、监测时间。时间格式为(2020/11/17))</p>
|
{# <p class="help-block">请上传csv文件(文件表头依次为:错误、建议、定位、新媒体类型、账号、发文时间、标题、市、监测时间。时间格式为(2020/11/17))</p>#}
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-success">点击上传</button>
|
<button type="submit" class="btn btn-success" style="margin-left: 40%">点击上传</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -29,22 +29,27 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">新媒体舆情数据录入</div>
|
<div class="panel-heading">时效性监测数据录入</div>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<!-- Default panel contents -->
|
<!-- Default panel contents -->
|
||||||
<form action="{% url 'backstage-new-media-public-opinion' %}" method="post"
|
<form action="{% url 'backstage-new-media-public-opinion' %}" method="post"
|
||||||
enctype="multipart/form-data">{% csrf_token %}
|
enctype="multipart/form-data">{% csrf_token %}
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-6">
|
||||||
<label for="date">时间</label>
|
<label for="date">时间</label>
|
||||||
<input type="date" class="form-control" id="source"
|
<input type="date" class="form-control" id="source"
|
||||||
name="date">
|
name="date">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group col-md-6">
|
||||||
|
<label for="date_length">时间跨度(单位:个月)</label>
|
||||||
|
<input type="text" class="form-control" id="source"
|
||||||
|
name="date_length">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-12" style="margin-left: 10%">
|
||||||
<label for="exampleInputFile">点击上传文件</label>
|
<label for="exampleInputFile">点击上传文件</label>
|
||||||
<input type="file" id="exampleInputFile" name="file">
|
<input type="file" id="exampleInputFile" name="file">
|
||||||
<p class="help-block">请上传csv文件(文件表头依次为:新媒体类型,新媒体名称,主体类型,代表主体名称,市,县/区,备注,结果,更新次数,最大连续静默日数,开始时间,结束时间。时间格式为(2020/11/17).更新次数和最大连续静默日必须是数字)</p>
|
{# <p class="help-block">请上传csv文件(文件表头依次为:新媒体类型,新媒体名称,主体类型,代表主体名称,市,县/区,备注,结果,更新次数,最大连续静默日数,开始时间,结束时间。时间格式为(2020/11/17).更新次数和最大连续静默日必须是数字)</p>#}
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-success">点击上传</button>
|
<button type="submit" class="btn btn-success" style="margin-left: 40%">点击上传</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import xlrd
|
import xlrd
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -8,107 +10,87 @@ from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from xlrd import xldate_as_tuple, xldate_as_datetime
|
||||||
|
|
||||||
from NewMediaMonitoring import settings
|
from NewMediaMonitoring import settings
|
||||||
from dashboard.models import TimelinessMonitoring, Wrongly, Comment
|
from dashboard.models import TimelinessMonitoring, Wrongly, Comment, Area_code_2020
|
||||||
|
|
||||||
|
|
||||||
def backstage_new_media_public_opinion(request):
|
def backstage_new_media_public_opinion(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
filename = request.FILES.get('file')
|
filename = request.FILES.get('file')
|
||||||
date = request.POST.get("date")
|
date = request.POST.get("date")
|
||||||
|
date_length = request.POST.get("date_length")
|
||||||
if not os.path.exists(settings.MEDIA_ROOT):
|
if not os.path.exists(settings.MEDIA_ROOT):
|
||||||
os.makedirs(settings.MEDIA_ROOT)
|
os.makedirs(settings.MEDIA_ROOT)
|
||||||
if filename is None:
|
if filename is None:
|
||||||
messages.error(request, '请选择要上传的文件!!!')
|
messages.error(request, '请选择要上传的文件!!!')
|
||||||
return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
||||||
if str(filename).split('.')[1] == 'csv':
|
|
||||||
data = filename.read().decode("utf-8")
|
|
||||||
line = str(data).split('\n')
|
|
||||||
for l in line:
|
|
||||||
v = l.split(',')
|
|
||||||
# print(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11])
|
|
||||||
# if str(v[0]) != '新媒体类型' or str(v[1]) != '新媒体名称' or str(v[2]) != '主体类型' or str(v[3]) != '代表主体名称' or str(v[4]) != '市' or str(v[6]) != '备注' or str(v[7]) != '结果' or str(v[8]) != '更新次数' or str(v[9]) != '最大连续静默日数' or str(v[10]) != '开始时间' or str(v[11]) != '结束时间':
|
|
||||||
# messages.error(request, '请上传正确的文件格式!!!')
|
|
||||||
# return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
|
||||||
mat1 = None
|
|
||||||
mat2 = None
|
|
||||||
# if v[10] is not None and v[11] is not None:
|
|
||||||
# mat1 = re.search(r"(\d{4}/\d{1,2}/\d{1,2})", v[10])
|
|
||||||
# mat2 = re.search(r"(\d{4}/\d{1,2}/\d{1,2})", v[11])
|
|
||||||
# if mat1 is None or mat2 is None:
|
|
||||||
# messages.error(request, '请上传正确的时间格式!!!')
|
|
||||||
# return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
|
||||||
|
|
||||||
|
data = xlrd.open_workbook(filename=None, file_contents=filename.read())
|
||||||
|
table = data.sheets()[0]
|
||||||
|
for row in range(table.nrows):
|
||||||
|
v = table.row_values(row)[1]
|
||||||
|
if v != '单位全称':
|
||||||
try:
|
try:
|
||||||
if v[8] != '更新次数':
|
identificationcode = table.row_values(row)[3]
|
||||||
# if v[8].isdigit():
|
n_type = table.row_values(row)[7]
|
||||||
n_type = v[0]
|
results = table.row_values(row)[21]
|
||||||
n_name = v[1]
|
update = table.row_values(row)[22]
|
||||||
o_type = v[2]
|
silent = table.row_values(row)[23]
|
||||||
o_name = v[3]
|
start_data = table.row_values(row)[24]
|
||||||
city = v[4]
|
d = datetime(*xldate_as_tuple(start_data, 0))
|
||||||
counties = v[5]
|
cell_start = d.strftime('%Y-%m-%d')
|
||||||
remark = v[6]
|
end_data = table.row_values(row)[25]
|
||||||
results = v[7]
|
e = datetime(*xldate_as_tuple(end_data, 0))
|
||||||
update = v[8]
|
cell_end = e.strftime('%Y-%m-%d')
|
||||||
silet = v[9]
|
city = table.row_values(row)[10]
|
||||||
start_data = v[10]
|
cell_city = Area_code_2020.objects.get(name=city).code
|
||||||
end_data = v[11]
|
district = table.row_values(row)[11]
|
||||||
timelinessmonitoring = TimelinessMonitoring(n_type=n_type, n_name=n_name, o_type=o_type,
|
cell_district = Area_code_2020.objects.get(name=district).code
|
||||||
o_name=o_name,
|
timelinessmonitoring = TimelinessMonitoring(identificationcode=identificationcode, n_type=n_type,
|
||||||
city=city, counties=counties, remark=remark,
|
results=results, update=update, silent=silent,
|
||||||
results=results, update=update, silet=silet,
|
start_data=cell_start, end_data=cell_end, date=date,
|
||||||
start_data=start_data, end_data=end_data,
|
date_length=date_length,city=cell_city,district=cell_district)
|
||||||
comment=0, date=date)
|
|
||||||
timelinessmonitoring.save()
|
timelinessmonitoring.save()
|
||||||
# else:
|
|
||||||
# messages.error(request, '更新次数只能为数字!!!')
|
|
||||||
# return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
|
||||||
except:
|
except:
|
||||||
print(v)
|
pass
|
||||||
|
messages.success(request,"上传成功")
|
||||||
else:
|
|
||||||
messages.error(request, '请上传正确的文件类型!!!')
|
|
||||||
return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
|
||||||
|
|
||||||
return render(request, 'backstage/backstage_new_media_public_opinion.html')
|
return render(request, 'backstage/backstage_new_media_public_opinion.html')
|
||||||
|
|
||||||
|
|
||||||
def backstage_error(request):
|
def backstage_error(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
filename = request.FILES.get('file')
|
filename = request.FILES.get('file')
|
||||||
|
city = request.POST.get('city')
|
||||||
|
jc_date = request.POST.get('jc_date')
|
||||||
if not os.path.exists(settings.MEDIA_ROOT):
|
if not os.path.exists(settings.MEDIA_ROOT):
|
||||||
os.makedirs(settings.MEDIA_ROOT)
|
os.makedirs(settings.MEDIA_ROOT)
|
||||||
if filename is None:
|
if filename is None:
|
||||||
messages.error(request, '请选择要上传的文件!!!')
|
messages.error(request, '请选择要上传的文件!!!')
|
||||||
return HttpResponseRedirect('/backstage/backstage/error/')
|
return HttpResponseRedirect('/backstage/backstage/error/')
|
||||||
if str(filename).split('.')[1] == 'csv':
|
data = xlrd.open_workbook(filename=None, file_contents=filename.read())
|
||||||
data = filename.read().decode("utf-8")
|
table = data.sheets()[0]
|
||||||
line = str(data).split('\n')
|
for row in range(table.nrows):
|
||||||
for l in line:
|
v = table.row_values(row)[1]
|
||||||
v = l.split(',')
|
if v != '建议':
|
||||||
try:
|
try:
|
||||||
if v[0] != '错误':
|
error = table.row_values(row)[0]
|
||||||
print(v[0])
|
idea = table.row_values(row)[1]
|
||||||
error = v[0]
|
site = table.row_values(row)[4]
|
||||||
idea = v[1]
|
n_type = table.row_values(row)[2]
|
||||||
site = v[2]
|
n_name = table.row_values(row)[3]
|
||||||
n_type = v[3]
|
date = table.row_values(row)[5]
|
||||||
n_name = v[4]
|
d = datetime(*xldate_as_tuple(date, 0))
|
||||||
date = v[5]
|
cell_date = d.strftime('%Y-%m-%d')
|
||||||
title = v[6]
|
title = table.row_values(row)[6]
|
||||||
city = v[7]
|
wrongly = Wrongly(error=error, idea=idea, site=site, n_type=n_type, n_name=n_name, date=cell_date,
|
||||||
jc_date = v[8]
|
|
||||||
wrongly = Wrongly(error=error, idea=idea, site=site, n_type=n_type, n_name=n_name, date=date,
|
|
||||||
title=title, city=city, jc_date=jc_date)
|
title=title, city=city, jc_date=jc_date)
|
||||||
wrongly.save()
|
wrongly.save()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print(v)
|
pass
|
||||||
|
messages.success(request,'上传成功')
|
||||||
|
|
||||||
else:
|
|
||||||
messages.error(request, '请上传正确的文件类型!!!')
|
|
||||||
return HttpResponseRedirect('/backstage/backstage/error/')
|
|
||||||
return render(request, 'backstage/backstage-error.html')
|
return render(request, 'backstage/backstage-error.html')
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,5 +126,6 @@ def backstage_comment(request):
|
||||||
return HttpResponseRedirect('/backstage/backstage/comment/')
|
return HttpResponseRedirect('/backstage/backstage/comment/')
|
||||||
return render(request, 'backstage/backstage-comment.html')
|
return render(request, 'backstage/backstage-comment.html')
|
||||||
|
|
||||||
|
|
||||||
def backstage_user(request):
|
def backstage_user(request):
|
||||||
return render(request, '')
|
return render(request, '')
|
|
@ -526,20 +526,19 @@ class Toutiao(NewMedia):
|
||||||
# 今日头条数据
|
# 今日头条数据
|
||||||
class Toutiao_data(models.Model):
|
class Toutiao_data(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
title = models.CharField('标题', max_length=256, null=True, blank=True)
|
|
||||||
url = models.CharField('链接', max_length=256, null=True, blank=True)
|
|
||||||
img = models.CharField('缩略图', max_length=256, null=True, blank=True)
|
|
||||||
count = models.CharField('阅读数', max_length=256, null=True, blank=True)
|
|
||||||
commentcount = models.CharField(
|
|
||||||
'评论数', max_length=256, null=True, blank=True)
|
|
||||||
reply = models.CharField('作者回复数', max_length=256, null=True, blank=True)
|
|
||||||
year = models.CharField('年', max_length=256, null=True, blank=True)
|
|
||||||
month = models.CharField('月', max_length=256, null=True, blank=True)
|
|
||||||
day = models.CharField('日', max_length=256, null=True, blank=True)
|
|
||||||
content = models.TextField('正文', null=True, blank=True)
|
|
||||||
comment = models.TextField('评论', null=True, blank=True)
|
|
||||||
toutiao = models.ForeignKey(
|
toutiao = models.ForeignKey(
|
||||||
Toutiao, on_delete=models.CASCADE, null=True, blank=True)
|
Toutiao, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
tid = models.CharField('tid', max_length=256, null=True, blank=True)
|
||||||
|
celltype = models.CharField('celltype', max_length=256, null=True, blank=True)
|
||||||
|
title = models.CharField('标题', max_length=256, null=True, blank=True)
|
||||||
|
content = models.TextField('内容',null=True,blank=True)
|
||||||
|
time = models.CharField('时间', max_length=256, null=True, blank=True)
|
||||||
|
url = models.CharField('链接', max_length=256, null=True, blank=True)
|
||||||
|
commentcount = models.IntegerField('评论量', null=True, blank=True)
|
||||||
|
readnum = models.IntegerField('阅读量', null=True, blank=True)
|
||||||
|
likenum = models.IntegerField('点赞量', null=True, blank=True)
|
||||||
|
shownum = models.IntegerField('点击量', null=True, blank=True)
|
||||||
|
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
|
@ -627,7 +626,7 @@ class Qita_jc(models.Model):
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.mewnedia.name
|
return self.mewnedia.code
|
||||||
|
|
||||||
|
|
||||||
# 5级地名库
|
# 5级地名库
|
||||||
|
@ -727,29 +726,27 @@ class NewmediaSentimentToutiao(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
# 时效性监测临时表
|
# 时效性监测临时表
|
||||||
|
|
||||||
|
|
||||||
class TimelinessMonitoring(models.Model):
|
class TimelinessMonitoring(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
n_type = models.CharField('新媒体类型', max_length=256, 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)
|
# name = models.ForeignKey(NewMedia,on_delete=models.CASCADE)
|
||||||
o_type = models.CharField('主体类型', max_length=256, null=True, blank=True)
|
identificationcode = 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)
|
results = models.CharField('监测结果', max_length=256, null=True, blank=True)
|
||||||
update = models.IntegerField('更新次数', null=True, blank=True)
|
update = models.IntegerField('更新次数', null=True, blank=True)
|
||||||
silet = models.CharField('最大连续静默日数', max_length=256, null=True, blank=True)
|
silent = models.IntegerField('静默日数', null=True, blank=True)
|
||||||
start_data = models.CharField(
|
start_data = models.CharField(
|
||||||
'开始时间', max_length=256, null=True, blank=True)
|
'开始时间', max_length=256, null=True, blank=True)
|
||||||
end_data = models.CharField('结束时间', max_length=256, null=True, blank=True)
|
end_data = models.CharField('结束时间', max_length=256, null=True, blank=True)
|
||||||
comment = models.IntegerField('评论次数', null=True, blank=True)
|
date = models.CharField('时间', max_length=256, null=True, blank=True)
|
||||||
date = models.CharField('最近更新时间', max_length=256, null=True, blank=True)
|
date_length = models.CharField('时间', max_length=256, null=True, blank=True)
|
||||||
|
city = models.CharField('市', max_length=256, null=True, blank=True)
|
||||||
|
district = models.CharField('县', max_length=256, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.n_name
|
return self.id
|
||||||
|
|
||||||
|
|
||||||
# 错别字临时表
|
# 错别字临时表
|
||||||
|
|
|
@ -478,6 +478,7 @@ def user_search_by_keyword(request):
|
||||||
# userpaginator = paginator.page(1)
|
# userpaginator = paginator.page(1)
|
||||||
# except EmptyPage:
|
# except EmptyPage:
|
||||||
# userpaginator = paginator.page(paginator.num_pages)
|
# userpaginator = paginator.page(paginator.num_pages)
|
||||||
|
user_count = None
|
||||||
if userpaginator:
|
if userpaginator:
|
||||||
user_count = userpaginator.count()
|
user_count = userpaginator.count()
|
||||||
userallinfo = []
|
userallinfo = []
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import pymysql
|
||||||
|
|
||||||
|
host = "210.72.82.249"
|
||||||
|
user = "pom"
|
||||||
|
password = "pomWechat2020"
|
||||||
|
port = 3306
|
||||||
|
database = 'pomdb'
|
||||||
|
mysql = pymysql.connect(host=host,user=user,password=password,port=port,database=database)
|
||||||
|
cursor = mysql.cursor()
|
||||||
|
|
||||||
|
sql = 'select * from toutiao_article where id = "65226"'
|
||||||
|
cursor.execute(sql)
|
||||||
|
|
||||||
|
results = cursor.fetchall()
|
||||||
|
for r in results:
|
||||||
|
print(r)
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
951
monitor/views.py
951
monitor/views.py
File diff suppressed because it is too large
Load Diff
|
@ -15,3 +15,4 @@
|
||||||
#aliyun-python-sdk-dyvmsapi
|
#aliyun-python-sdk-dyvmsapi
|
||||||
#pandas
|
#pandas
|
||||||
#xlrd
|
#xlrd
|
||||||
|
# pymysql
|
||||||
|
|
Loading…
Reference in New Issue