python

html hsdata_file_name_change(途中)

import re
import glob
import os
import shutil
import csv


# 同フォルダ内のhtmlファイル名を取得
file_name = glob.glob('*.csv')[0]

if "~" not in file_name:
    print("実行する")
    
    # ここにコードを記述
    
    f = open(file_name)
    reader = csv.reader(f)
    
    l = [row for row in reader]
    
    beginning=l[1][0]
    
    ending=l[-1][0]
    
    beginning.split("/")
    start_date=beginning.split("/")[2] + "-" + beginning.split("/")[0] + "-" + beginning.split("/")[1]
    
    ending.split("/")
    end_date=ending.split("/")[2] + "-" + ending.split("/")[0] + "-" + ending.split("/")[1]
    
    start_date + "~" + end_date
    
    new_file_name=file_name.replace("FromDownloader","")
    new_file_name=new_file_name.replace("_BidAndAsk","")

    new_file_name =  new_file_name + "["+start_date + "~" + end_date+"]" 
    
    f.close()
    
    os.rename(file_name,new_file_name)
else:
    print("実行しない")
Was this helpful?