標簽歸檔:pushweb

pushWeb 小更新

以前寫過一篇PushWeb 采集站點信息發布的最佳方案(http://www.okfdzs53.com/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