import os,sys,time,urllib2,difflib
url = "远程文件url"
def getRemoteFileInfo(url, proxy=None):
opener = urllib2.build_opener()
if proxy:
if url.lower().startswith('https://'):
opener.add_handler(urllib2.ProxyHandler({'https' : proxy}))
else:
opener.add_handler(urllib2.ProxyHandler({'http' : proxy}))
try:
request = urllib2.Request(url)
request.get_method = lambda: 'HEAD'
response = opener.open(request)
response.read()
except Exception, e:
return 0
else:
return dict(response.headers)
def GMT2BJ(modify_time):
ltime= time.strptime(modify_time[5:25], "%d %b %Y %H:%M:%S")
bj_time=time.localtime(time.mktime(ltime)+8*60*60)
dateStr="%u-%02u-%02u"%(bj_time.tm_year,bj_time.tm_mon,bj_time.tm_mday)
timeStr="%02u:%02u:%02u"%(bj_time.tm_hour,bj_time.tm_min,bj_time.tm_sec)
return dateStr+' '+timeStr
def isModifyedToday(modify_time):
modify_time = time.strptime(modify_time[5:25], "%d %b %Y %H:%M:%S")
modify_time = time.localtime(time.mktime(modify_time)+8*60*60)
current_time = time.localtime()
print modify_time
print current_time
if current_time.tm_year == modify_time.tm_year and current_time.tm_mday == modify_time.tm_mday and current_time.tm_mon == modify_time.tm_mon :
return True
else:
return False
if __name__ == "__main__":
fileInfo = getRemoteFileInfo(url)
modify_time = fileInfo['last-modified']
if isModifyedToday(modify_time):
print "文件有更新..."
a = open('E:/python/a.txt', 'U').readlines()
b = open('E:/python/b.txt', 'U').readlines()
diff = difflib.ndiff(a, b)
sys.stdout.writelines(diff)