#add message
This commit is contained in:
parent
fd15ae8736
commit
3d3d94640d
|
@ -34,17 +34,22 @@
|
|||
<!-- Default panel contents -->
|
||||
<form action="{% url 'backstage-error' %}" method="post"
|
||||
enctype="multipart/form-data">{% csrf_token %}
|
||||
{# <div class="form-group col-md-4">#}
|
||||
{# <label for="date">时间</label>#}
|
||||
{# <input type="date" class="form-control" id="source"#}
|
||||
{# name="date">#}
|
||||
{# </div>#}
|
||||
<div class="form-group">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="city">市</label>
|
||||
<input type="text" class="form-control" id="source"
|
||||
name="city">
|
||||
</div>
|
||||
<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>
|
||||
<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>
|
||||
<button type="submit" class="btn btn-success">点击上传</button>
|
||||
<button type="submit" class="btn btn-success" style="margin-left: 40%">点击上传</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -29,22 +29,27 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">新媒体舆情数据录入</div>
|
||||
<div class="panel-heading">时效性监测数据录入</div>
|
||||
<div class="panel panel-default">
|
||||
<!-- Default panel contents -->
|
||||
<form action="{% url 'backstage-new-media-public-opinion' %}" method="post"
|
||||
enctype="multipart/form-data">{% csrf_token %}
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="date">时间</label>
|
||||
<input type="date" class="form-control" id="source"
|
||||
name="date">
|
||||
</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>
|
||||
<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>
|
||||
<button type="submit" class="btn btn-success">点击上传</button>
|
||||
<button type="submit" class="btn btn-success" style="margin-left: 40%">点击上传</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import csv
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
import xlrd
|
||||
from django.contrib import messages
|
||||
|
@ -8,107 +10,87 @@ from django.http import HttpResponse, HttpResponseRedirect
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from xlrd import xldate_as_tuple, xldate_as_datetime
|
||||
|
||||
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):
|
||||
if request.method == 'POST':
|
||||
filename = request.FILES.get('file')
|
||||
date = request.POST.get("date")
|
||||
date_length = request.POST.get("date_length")
|
||||
if not os.path.exists(settings.MEDIA_ROOT):
|
||||
os.makedirs(settings.MEDIA_ROOT)
|
||||
if filename is None:
|
||||
messages.error(request, '请选择要上传的文件!!!')
|
||||
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:
|
||||
if v[8] != '更新次数':
|
||||
# if v[8].isdigit():
|
||||
n_type = v[0]
|
||||
n_name = v[1]
|
||||
o_type = v[2]
|
||||
o_name = v[3]
|
||||
city = v[4]
|
||||
counties = v[5]
|
||||
remark = v[6]
|
||||
results = v[7]
|
||||
update = v[8]
|
||||
silet = v[9]
|
||||
start_data = v[10]
|
||||
end_data = v[11]
|
||||
timelinessmonitoring = TimelinessMonitoring(n_type=n_type, n_name=n_name, o_type=o_type,
|
||||
o_name=o_name,
|
||||
city=city, counties=counties, remark=remark,
|
||||
results=results, update=update, silet=silet,
|
||||
start_data=start_data, end_data=end_data,
|
||||
comment=0, date=date)
|
||||
identificationcode = table.row_values(row)[3]
|
||||
n_type = table.row_values(row)[7]
|
||||
results = table.row_values(row)[21]
|
||||
update = table.row_values(row)[22]
|
||||
silent = table.row_values(row)[23]
|
||||
start_data = table.row_values(row)[24]
|
||||
d = datetime(*xldate_as_tuple(start_data, 0))
|
||||
cell_start = d.strftime('%Y-%m-%d')
|
||||
end_data = table.row_values(row)[25]
|
||||
e = datetime(*xldate_as_tuple(end_data, 0))
|
||||
cell_end = e.strftime('%Y-%m-%d')
|
||||
city = table.row_values(row)[10]
|
||||
cell_city = Area_code_2020.objects.get(name=city).code
|
||||
district = table.row_values(row)[11]
|
||||
cell_district = Area_code_2020.objects.get(name=district).code
|
||||
timelinessmonitoring = TimelinessMonitoring(identificationcode=identificationcode, n_type=n_type,
|
||||
results=results, update=update, silent=silent,
|
||||
start_data=cell_start, end_data=cell_end, date=date,
|
||||
date_length=date_length,city=cell_city,district=cell_district)
|
||||
timelinessmonitoring.save()
|
||||
# else:
|
||||
# messages.error(request, '更新次数只能为数字!!!')
|
||||
# return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
||||
except:
|
||||
print(v)
|
||||
|
||||
else:
|
||||
messages.error(request, '请上传正确的文件类型!!!')
|
||||
return HttpResponseRedirect('/backstage/backstage/newmedia/public/opinion/')
|
||||
|
||||
pass
|
||||
messages.success(request,"上传成功")
|
||||
return render(request, 'backstage/backstage_new_media_public_opinion.html')
|
||||
|
||||
|
||||
def backstage_error(request):
|
||||
if request.method == 'POST':
|
||||
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):
|
||||
os.makedirs(settings.MEDIA_ROOT)
|
||||
if filename is None:
|
||||
messages.error(request, '请选择要上传的文件!!!')
|
||||
return HttpResponseRedirect('/backstage/backstage/error/')
|
||||
if str(filename).split('.')[1] == 'csv':
|
||||
data = filename.read().decode("utf-8")
|
||||
line = str(data).split('\n')
|
||||
for l in line:
|
||||
v = l.split(',')
|
||||
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:
|
||||
if v[0] != '错误':
|
||||
print(v[0])
|
||||
error = v[0]
|
||||
idea = v[1]
|
||||
site = v[2]
|
||||
n_type = v[3]
|
||||
n_name = v[4]
|
||||
date = v[5]
|
||||
title = v[6]
|
||||
city = v[7]
|
||||
jc_date = v[8]
|
||||
wrongly = Wrongly(error=error, idea=idea, site=site, n_type=n_type, n_name=n_name, date=date,
|
||||
error = table.row_values(row)[0]
|
||||
idea = table.row_values(row)[1]
|
||||
site = table.row_values(row)[4]
|
||||
n_type = table.row_values(row)[2]
|
||||
n_name = table.row_values(row)[3]
|
||||
date = table.row_values(row)[5]
|
||||
d = datetime(*xldate_as_tuple(date, 0))
|
||||
cell_date = d.strftime('%Y-%m-%d')
|
||||
title = table.row_values(row)[6]
|
||||
wrongly = Wrongly(error=error, idea=idea, site=site, n_type=n_type, n_name=n_name, date=cell_date,
|
||||
title=title, city=city, jc_date=jc_date)
|
||||
wrongly.save()
|
||||
|
||||
except:
|
||||
print(v)
|
||||
pass
|
||||
messages.success(request,'上传成功')
|
||||
|
||||
else:
|
||||
messages.error(request, '请上传正确的文件类型!!!')
|
||||
return HttpResponseRedirect('/backstage/backstage/error/')
|
||||
return render(request, 'backstage/backstage-error.html')
|
||||
|
||||
|
||||
|
@ -144,5 +126,6 @@ def backstage_comment(request):
|
|||
return HttpResponseRedirect('/backstage/backstage/comment/')
|
||||
return render(request, 'backstage/backstage-comment.html')
|
||||
|
||||
|
||||
def backstage_user(request):
|
||||
return render(request,'')
|
||||
return render(request, '')
|
||||
|
|
|
@ -526,20 +526,19 @@ class Toutiao(NewMedia):
|
|||
# 今日头条数据
|
||||
class Toutiao_data(models.Model):
|
||||
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, 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)
|
||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||
|
||||
|
@ -627,7 +626,7 @@ class Qita_jc(models.Model):
|
|||
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.mewnedia.name
|
||||
return self.mewnedia.code
|
||||
|
||||
|
||||
# 5级地名库
|
||||
|
@ -727,29 +726,27 @@ class NewmediaSentimentToutiao(models.Model):
|
|||
|
||||
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)
|
||||
# name = models.ForeignKey(NewMedia,on_delete=models.CASCADE)
|
||||
identificationcode = 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)
|
||||
silet = models.CharField('最大连续静默日数', max_length=256, null=True, blank=True)
|
||||
silent = models.IntegerField('静默日数', 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('评论次数', 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):
|
||||
return self.n_name
|
||||
return self.id
|
||||
|
||||
|
||||
# 错别字临时表
|
||||
|
|
|
@ -478,6 +478,7 @@ def user_search_by_keyword(request):
|
|||
# userpaginator = paginator.page(1)
|
||||
# except EmptyPage:
|
||||
# userpaginator = paginator.page(paginator.num_pages)
|
||||
user_count = None
|
||||
if userpaginator:
|
||||
user_count = userpaginator.count()
|
||||
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
|
||||
#pandas
|
||||
#xlrd
|
||||
# pymysql
|
||||
|
|
Loading…
Reference in New Issue