From b646953e80c0f7cb3db84836c90664fc94fb8431 Mon Sep 17 00:00:00 2001 From: xieshen <1397910458@qq.com> Date: Sun, 6 Dec 2020 00:39:07 +0800 Subject: [PATCH] =?UTF-8?q?#=E9=A6=96=E9=A1=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitor/views.py | 9 ++++- update_newmedia.py | 93 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/monitor/views.py b/monitor/views.py index f17e793..4073ac2 100644 --- a/monitor/views.py +++ b/monitor/views.py @@ -131,8 +131,13 @@ def timeliness_monitoring_weixin(request): 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) + if now.month == 12: + this_month_end = datetime.datetime(now.year, now.month , 1) - timedelta(days=1) + datetime.timedelta( + hours=23, minutes=59, seconds=59) + else: + this_month_end = datetime.datetime(now.year, now.month, 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()) diff --git a/update_newmedia.py b/update_newmedia.py index 93d45b4..a4e310c 100644 --- a/update_newmedia.py +++ b/update_newmedia.py @@ -5,14 +5,95 @@ 3、与数据库中的数据逐项对比 ''' import csv +import uuid +import psycopg2 as psycopg2 -def get_csv(path): - with open(path, encoding='utf-8') as csvfile: - reader = csv.reader(csvfile) - for r in reader: +# code = None +# alias = None +# attention = None +# remark = None +# identificationcode = None +# function = None +# articleurl = None +# weixinid = None +# type = None +G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#' - print(r) +def get_csv_weixin(path): + with open("D:/2020/新媒体监测/新媒体对比结果_其他.csv", "w", newline='') as csvfile: + writer = csv.writer(csvfile) + writer.writerow( + ["序号", "冲突账号"]) + with psycopg2.connect(G2) as connection: + with open(path, encoding='utf-8') as csvfile: + reader = csv.reader(csvfile) + for r in reader: + if r[1] != '单位全称': + if '头条' not in r[7] and '微信' not in r[7] and '微博' not in r[7] and '抖音' not in r[7]: + name = r[1] + code = r[4] + identificationcode = r[3] + function = r[8] + articleurl = r[12] + biz = r[13] + province = None + cities = None + district = None + d_name = None + c_name = None + p_name = None + + print(r) + try: + with connection.cursor() as cursor_p: + cursor_p.execute( + "select * from dashboard_area_code_2020 where name = '%s'" % (r[9])) + for p in cursor_p: + province = p[1] + p_name = p[2] + with connection.cursor() as cursor_c: + cursor_c.execute( + "select * from dashboard_area_code_2020 where name = '%s'" % (r[10])) + for c in cursor_c: + cities = c[1] + c_name = c[2] + with connection.cursor() as cursor_d: + cursor_d.execute( + "select * from dashboard_area_code_2020 where name = '%s'" % (r[11])) + for d in cursor_d: + district = d[1] + d_name = d[2] + print(code) + with connection.cursor() as cursor: + cursor.execute( + "select * from dashboard_qita where code = '%s'" % (code)) + # connection.commit() + + for c in cursor: + print(str(c[10]) + "1111111111111111111111") + with connection.cursor() as cursor2: + cursor2.execute( + "select * from dashboard_organization where id = '%s'" % (c[10])) + for c2 in cursor2: + print(str(c2[0]) + "55555555555555555555555") + + if str(name) == str(c2[1]) and str(province) == str(c2[3]) and str( + cities) == str(c2[4]) and str(district) == str(c2[5]) and str( + code) == str(c[1]) and str(identificationcode) == str( + c[13]) and str(biz) == str(c[9]): + print(c2) + else: + writer.writerow( + [r[0], name, code, identificationcode, biz, p_name, c_name, + d_name]) + writer.writerow( + [r[0], c2[1], c[1], c[13], c[9], c2[3], c2[4], c2[5]]) + + except: + writer.writerow( + [r[0], name, code, identificationcode, biz, p_name, c_name, + d_name]) if __name__ == '__main__': - get_csv('D:/2020/新媒体监测/TASK_ALL.csv') \ No newline at end of file + get_csv_weixin('D:/2020/新媒体监测/TASK_ALL.csv') \ No newline at end of file