newmediamonitoring/test.py

39 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
import csv
import re
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=newmediaDB1 user=newmedia password=newmedia2020!@#'
def insert_area(title,date, code,content):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
'insert into monitor_test(id, title,date, code,content) values (%s,%s, %s,%s,%s)'
, (str(id),title,date, code,content))
connection.commit()
return code
if __name__ == '__main__':
with open('D:/2020/舆论监测平台/新媒体监测数据/天水/天水20200822-20200922/天水20200822-20200922数据整理/天水微信正文.csv',encoding='utf8') as csvfile:
reader = csv.reader(csvfile)
try:
for r in reader:
print(r)
title = r[0]
date = r[1]
code = r[2]
content = r[5]
insert_area(title, date, code, content)
except:
pass