python - How do I read only some of the line using line.rstrip -
i have simple python script that's downloading dated files server. script reads log file see if file has been downloaded or not , makes decision download file or skip it.
if file not in log file (meaning has not been downloaded yet), downloads file , writes file name log. when script runs again, doesn't download file again.
how check see if file exists in log using
f = open('testfile.txt', 'r+') line in f: if line.rstrip() == mysales + date + file: mysalesdownload = "true" elif line.rstrip() == myproducts + date + file: myproductsdownload = "true" else: continue
mysales + date + file - mysales_2014-05-01.txt in log file.
the problem want add delimiter (;) , downloaded date file. downloaded date tells me when script downloaded data.
f.write( mysales + date + file + ";" + datetime.date.today() + "\n");
however, throws wrench reading of log file now. dates dynamic , data run on night. so, bearing in mind line this:
mysales_2014-05-01.txt;2014-05-02
how read semicolon don't download same file twice if script runs on night?
change line:
if line.rstrip() == mysales + date + file:
to:
if line.rstrip()[:line.rstrip().find(';')] == mysales + date + file:
and on.
Comments
Post a Comment