标签归档:pushweb

pushWeb 小更新

以前写过一篇PushWeb 采集站点信息发布的最佳方案(http://www.miaoqiyuan.cn/p/pushweb),用了很久,现在数据量大了,导入速度很慢(主要原因是导入一条记录,自动修复一次数据),在此,我修改了一下代码,暂且算是升级到1.01吧:

'pushWeb 1.01

'刷新时间
const pushWeb_flush_Time=600000
'数据库路径
const pushWeb_dbPath="D:\WebDesign\Products\pushWeb\DB\PushWebDB.mdb"


function pushWeb()
	on error resume next
	dim conn,rs,push_id,push_webid,push_sql
	dim web_db,web_name
	dim push_Arr,push_str
	
	set conn=createobject("ADODB.connection")
	conn.open "provider=microsoft.jet.oledb.4.0;data source="&pushWeb_dbPath
	set rs=conn.execute("select push_webid from push")
	if rs.eof then
		push_id=0
		wscript.echo "没有更新,"&pushWeb_flush_Time/1000&"秒后再检查..."
	else
		push_webid=rs(0)
	end if
	rs.close
	set rs=nothing
	
	if push_webid<>0 then
		'载入站点信息
		set rs=conn.execute("select web_name,web_db from web where web_id="&push_webid)
		if not rs.eof then
			web_name=rs(0)
			web_db=rs(1)
		else
			wscript.echo "错误的任务请求,"&pushWeb_flush_Time/1000&"秒后再检查..."
			exit function
		end if
		rs.close
		set rs=nothing
		
		'如果是合法的站点
		if web_db<>"" and web_name<>"" then
			wscript.echo "找到一个任务[站点名="&web_name&"],导入中..."
			'创建新的连接对象
			set newConn=CreateObject("ADODB.Connection")
			newConn.open web_db
			
			set rs=conn.execute("select push_sql from push where push_webid="&push_webid)
			
			do while not rs.eof
				push_sql=rs(0)
				push_Arr=split(push_sql,vbCrlf)
				for each push_str in push_Arr
					wscript.echo "插入一条数据..."
					if trim(push_str)<>"" then newConn.execute(trim(push_str))
				next
				rs.movenext
			loop

			'清空该站点下的所有任务
			conn.execute("delete from push where push_webid="&push_webid)

			wscript.sleep 100
			wscript.echo "开始修复数据..."
			'修复数据
			set repairRs=createobject("ADODB.recordset")
			repairRs.open "select * from NC_softList",newConn,3,2
			do while not repairRs.eof
				if not isnull(repairRs("Content")) then repairRs("Content")=replace(replace(repairRs("Content"),"{’}","'"),"{\n}",vbCrlf)
				repairRs.update
				repairRs.movenext
			loop
			repairRs.close
			set repairRs=nothing
			wscript.sleep 100
		end if
	else
		wscript.sleep pushWeb_flush_Time
	end if
	wscript.echo string(60,"=")
	call pushWeb()
end function


wscript.echo string(60,"=")
wscript.echo "pushWeb version:1.01"
wscript.echo "pushWeb Design:苗启源"
wscript.echo "pushWeb Home:miaoqiyuan.cn"
wscript.echo string(60,"=")
wscript.echo "pushWeb Starting..."
wscript.echo string(60,"=")
call pushWeb()

PushWeb 采集站点信息发布的最佳方案

PushWeb,应该算是我自造的一个词,Push发送,PushWeb则是把采集到的数据发送到站点的一个方案,临时使用vbscript脚本编写。那有的朋友可能会说CMS后台之类的,或者采集软件直接发上来不更好吗?原因如下:

CMS后台,来回复制好麻烦,而且容易出错。复制一篇两篇还可以,如果1000,10000呢?

采集软件发送,这个呢?如果信息都是采集的,按原来的列表顺序原封不动的发上来,恐怕。。。。而且在采集软件了并不是很方便的控制。

PushWeb的好处,可以同时发送数据到同一台服务器上的多个站点。为什么不用asp?因为一般iis站点,我习惯每个站点权限独立,假如pushWeb拥有所有站点的权限,安全性可能会降低。而且同时查询较多数据时,可能占用cpu过多,而影响web站点,而wscript可以通过累了sleep一下。另外后期准备为站点加些计划任务(比如自动生成,现在还是Beta0.1,仅供发布信息),这样只需要一个进程就可以了。

实现方法:

'pushWeb beta0.1

'刷新时间
const pushWeb_flush_Time=10000
'数据库路径
const pushWeb_dbPath="D:\WebDesign\Products\pushWeb\pushWebDB.mdb"


function pushWeb()
	dim conn,rs,push_id,push_webid,push_sql
	dim web_db,web_name
	dim push_Arr,push_str
	
	set conn=createobject("ADODB.connection")
	conn.open "provider=microsoft.jet.oledb.4.0;data source="&pushWeb_dbPath
	set rs=conn.execute("select push_id,push_webid,push_sql from push")
	if rs.eof then
		push_id=0
		wscript.echo "没有更新,"&pushWeb_flush_Time/1000&"秒后再检查..."
	else
		push_id=rs(0)
		push_webid=rs(1)
		push_sql=rs(2)
	end if
	rs.close
	set rs=nothing
	
	if push_id<>0 then
		conn.execute("delete from push where push_id="&push_id)
		set rs=conn.execute("select web_name,web_db from web where web_id="&push_webid)
		if not rs.eof then
			web_name=rs(0)
			web_db=rs(1)
		else
			wscript.echo "错误的任务请求,"&pushWeb_flush_Time/1000&"秒后再检查..."
		end if
		rs.close
		set rs=nothing
		conn.close
		
		if web_db<>"" and push_sql<>"" then
			wscript.echo "找到一个任务[站点名="&web_name&"],导入中..."
			
			conn.open web_db
			push_sql=replace(push_sql,vbCrlf,";")
			push_Arr=split(push_sql,";")
			for each push_str in push_Arr
				if trim(push_str)<>"" then conn.execute(trim(push_str))
			next
			
			conn.close
			set conn=nothing
			
			wscript.echo "导入完毕,"&pushWeb_flush_Time/1000&"秒后检查是否有新任务..."
		end if
	else
		wscript.sleep pushWeb_flush_Time
	end if
	wscript.echo string(60,"=")
	call pushWeb()
end function


wscript.echo string(60,"=")
wscript.echo "pushWeb version:beta 0.1"
wscript.echo "pushWeb Design:苗启源"
wscript.echo "pushWeb Home:miaoqiyuan.cn"
wscript.echo string(60,"=")
wscript.echo "pushWeb Starting..."
wscript.echo string(60,"=")
call pushWeb()

数据库设置:

push
push_id push_webid push_sql
1 1 insert into t(t,c)values(‘push_web_test’,’push_web_test’);insert into t(t,c)values(‘push_web_test’,’push_web_test’);
2 1 insert into t(t,c)values(‘push_web_test’,’push_web_test’)
insert into t(t,c)values(‘push_web_test’,’push_web_test’)
web
web_id web_name web_db
1 测试站点 provider=microsoft.jet.oledb.4.0;data source=D:\WebDesign\Products\pushWeb\test.mdb