都是用来更新一个rm视频参数文件的。最早学asp的时候顺便用vbs写了一个,后来学perl就又写了一个,现在学python,凑活也写一个。基本上算是我的一个入门程序。用途就是用简单正则表达式找到时间段,再将它更新为当天日期,更新后的数据存在temp.txt中。perl最短,python比较干净。
vbs:
dim regOR
set regOR=new regexp
regOR.ignorecase=True
regOR.global=True
regOR.pattern="^([0-9]{1})$"
dim mytime
mytime=date
yy=year(mytime)
mm=month(mytime)
dd=day(mytime)
if regOR.test(mm) then
mm=regOR.replace(mm,"0$1")
end if
if regOR.test(dd) then
dd=regOR.replace(dd,"0$1")
end if
mytime=yy & "-" & mm & "-" & dd
dest=yy & mm & dd
pattern1="(.*[^0-9])([0-9]{4}\-[0-9]{2}\-[0-9]{2})([^0-9].*)"
pattern2="(.*[^0-9])([0-9]{8})([^0-9].*)"
regOR.pattern=pattern1
dim tempstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("d:\shixian\temp.txt", True)
Set fr = fso.GetFile("d:\shixian\shixian.rpjf")
Set ts = fr.OpenAsTextStream(1,-2)
do until ts.AtEndOfStream
tempstring=ts.readline
if regOR.test(tempstring) then
tempstring=regOR.replace(tempstring,"$1" & mytime & "$3")
end if
regOR.pattern=pattern2
if regOR.test(tempstring) then
tempstring=regOR.replace(tempstring,"$1" & dest & "$3")
end if
regOR.pattern=pattern1
f.writeline(tempstring)
loop
ts.close
f.close
set regOR=nothing
set ts=nothing
set fr=nothing
set f=nothing
set fso=nothing
perl:
open(RPJF,"<c:/code/10161.rpjf") or die("can not open because of $!\n");
open(TEMP,">c:/code/temp.txt") or die("can not open because of $!\n");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
$mday = sprintf("%.2d",$mday);
$mon = sprintf("%.2d",$mon+1);
$year += 1900;
$timerF = "$year"."$mon"."$mday";
$timerS = "$year"."-"."$mon"."-"."$mday";
while(<RPJF>){
chomp();
$_=~s/(.*)([0-9]{8})(.*)/$1$timerF$3/;
$_=~s/(.*)([0-9]{4}\-[0-9]{2}\-[0-9]{2})(.*)/$1$timerS$3/;
print TEMP "$_\n";
}
close(RPJF);
close(TEMP);
python:
import re
import time
pattern_name = re.compile(r'[0-9]{8}')
pattern_info = re.compile(r'[0-9]{4}\-[0-9]{2}\-[0-9]{2}')
(year, month, day) = time.localtime()[:3]
name = '%d%.2d%.2d' % (year, month, day)
info = '%d-%.2d-%.2d' % (year, month, day)
try:
file_rpjf = open('shixian.rpjf', 'r')
file_temp = open('temp.txt', 'w')
try:
file_data = file_rpjf.readline()
while file_data != '':
file_data = pattern_name.sub(name, file_data)
file_data = pattern_info.sub(info, file_data)
file_temp.write(file_data)
file_data = file_rpjf.readline()
finally:
file_rpjf.close()
file_temp.close()
except IOError:
pass