首页 技术 正文
技术 2022年11月15日
0 收藏 664 点赞 2,881 浏览 2656 个字

本代码实现对163k地方门户网站系统发布信息的自动审核,以及对内容中链接全过滤

软件安装

Python 安装

http://www.python.org/download/

pymssql安装

https://code.google.com/p/pymssql/downloads/list

两者版本要对应。

程序代码

kill.py

#coding=utf8
#!/usr/bin/env python
# 网站自动审核系统import pymssql
import re
import sys
import datetimeDB_HOSTNAME = r'127.0.0.1:1433'
DB_USERNAME = 'username'
DB_PASSWORD = 'password'
DB_DATABASE = 'menhu_163k'reload(sys)
sys.setdefaultencoding('utf-8')#*******Connection MSSQL *************
stat = Falsetry:
ms_conn = pymssql.connect(host=DB_HOSTNAME, user=DB_USERNAME, password=DB_PASSWORD, database=DB_DATABASE, charset="UTF-8")
cur = ms_conn.cursor()
cur2 = ms_conn.cursor()
stat = True
except:
print 'Could nont connect to DB server.'def content_filter(content):
content = row[1]
re_a_qs = re.compile('<[aA][^>]*>')
content = re_a_qs.sub('', content)
re_a_js = re.compile('</[aA]>')
content = re_a_js.sub('', content)
return contentif stat:
str_log = ''
# 信息模块内容审核
strSQL = "SELECT detailsid, chrmark FROM mh163k_live WHERE iskill=0"
cur.execute(strSQL)
rowcount = 0
for row in cur:
rowcount += 1detailsid = str(row[0])
chrmark = content_filter(row[1])
#print row
strSQL = "UPDATE mh163k_live SET chrmark='" + chrmark + "', iskill=1 WHERE detailsid=" + str(detailsid)
#print strSQL
cur2.execute(strSQL)
ms_conn.commit()if rowcount:
str_log += str(datetime.datetime.now().strftime('%Y-%m,-%d %H:%M:%S')) + ': 信息模块审核' + str(rowcount) + "条\n"# 出租出售内容审核
strSQL = "SELECT id, chrmark FROM mh163k_house_chuzhu WHERE iskill=0"
cur.execute(strSQL)
rowcount = 0
for row in cur:
rowcount += 1detailsid = str(row[0])
chrmark = content_filter(row[1])
#print row
strSQL = "UPDATE mh163k_house_chuzhu SET chrmark='" + chrmark + "', iskill=1 WHERE id=" + str(detailsid)
#print strSQL
cur2.execute(strSQL)
ms_conn.commit()if rowcount:
str_log += str(datetime.datetime.now().strftime('%Y-%m,-%d %H:%M:%S')) + ': 出租出售审核' + str(rowcount) + "条\n"#房产中介 内容审核
strSQL = "SELECT maniddd FROM mh163k_house_zhongjie WHERE iskill=0"
cur.execute(strSQL)
rowcount = 0
for row in cur:
rowcount += 1row_id = str(row[0])
#print row
strSQL = "UPDATE mh163k_house_chuzhu SET iskill=1 WHERE manid=" + str(row_id)
#print strSQL
cur2.execute(strSQL)
ms_conn.commit()if rowcount:
str_log += str(datetime.datetime.now().strftime('%Y-%m,-%d %H:%M:%S')) + ': 房产中介审核' + str(rowcount) + "条\n"# 便民信息 内容审核
strSQL = "SELECT detailsid, chrcode FROM mh163k_live WHERE iskill=0"
cur.execute(strSQL)
rowcount = 0
for row in cur:
rowcount += 1row_id = str(row[0])
content = content_filter(row[1])
#print row
strSQL = "UPDATE mh163k_live SET chrcode='" + content + "', iskill=1 WHERE detailsid=" + str(row_id)
#print strSQL
cur2.execute(strSQL)
ms_conn.commit()if rowcount:
str_log += str(datetime.datetime.now().strftime('%Y-%m,-%d %H:%M:%S')) + ': 便民信息审核' + str(rowcount) + "条\n"print str_logms_conn.close()
f = open("./kill_log.txt", "a+")
f.write(str_log)
f.close#print '写入日志成功'
print '审核完成'

 kill.bat

CD C:\Python27
C:
python D:\python\kill.py

添加Windows计划任务

设成为每10分钟运行一次

下一篇: awk详解
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898