恐るべし chatGPT | 60歳を迎えて、思うこと。

60歳を迎えて、思うこと。

いつの間にか、「60」という年月が経ちました。
残り少ないか多いか?わかりませんが。
じじぃ~の「ひとりごと」を細々と続けられれば。。。

恐るべし chatGPT
 

# ==========================================================
import os
import glob
import shutil
import datetime as dt

# Change directory
os.chdir(r'C:\pypy\Dimora')
print(f"Current directory: {os.getcwd()}")

# User input for device selection
device_options = {
    1: "USB-1",
    2: "USB-2",
    3: "BRZ1020"
}

print('Select device:')
print('1: 2W101-USB-HDD-1')
print('2: 2W101-USB-HDD-2')
print('3: BRZ1020-USB-HDD-None')

try:
    select_hard = int(input('Enter the number for the target device: '))
    usb_name = device_options.get(select_hard, "Unknown")
    if usb_name == "Unknown":
        print('Hardware not recognized.')
    else:
        print(f'{usb_name} selected')
except ValueError:
    print('Invalid input. Please enter a number.')

# Create directory if it does not exist
output_path_2 = "F:\\D-DIGA\\_02-tsv-2W101"
os.makedirs(output_path_2, exist_ok=True)

# Define paths
input_path = "C:\\Users\\piyop\\Downloads\\"
output_path = "C:\\pypy\\Dimora\\"
timestamp = dt.datetime.now().strftime('番組表%Y-%m-%d_%H%M%S-2W101')
os.makedirs(timestamp, exist_ok=True)

# Move .tsv files to output_path_2
for item in glob.glob(input_path + "*.tsv"):
    shutil.copy2(item, output_path_2)

# Rename and move reclist*.tsv files
for i, item in enumerate(glob.glob(input_path + "reclist*.tsv")):
    shutil.copy2(item, os.path.join(output_path, f"RECLIST-{i}.csv"))

# Process RECLIST-0.csv
with open("RECLIST-0.csv", "r", encoding='UTF-8') as f:
    content = f.read()

# Replacements for formatting and content
replacements = {
    ",": ",",
    "\t": ",",
    "0:00": "0:01",
    "機器名称": "DMR-",
    "放送開始日時": "□放送開始日時□",
    "放送局名": "□放送局□",
    "録画時間 (分)": "分",
    "ジャンル": "ジャンル",
    "視聴/未視聴": "視聴",
    "録画モード": "MODE",
    "タイトル": "☆番組タイトル☆",
    "DMR-2W101": "2W101",
    "DMR-BRZ1020": "BRZ1020",
    "USB-HDD": usb_name,
    "内蔵HDD": "本体",
    "視聴済": "済",
    "未視聴": "未",
    "<スタンダードサイズ>": "[S]",
    "<レターボックスサイズ>": "[L]",
    "<字幕・レターボックスサイズ>": "[字][L]",
    "<字幕スーパー>": "[字]",
    "演劇/公演": "演劇",
    "アニメ/特撮": "アニメ特撮",
    "ドキュメンタリー/教養": "ドキュ教養",
    "趣味/教育": "趣味教育",
    "ニュース/報道": "報道",
    "バラエティ": "バラエティ",
    "情報/ワイドショー": "ワイドショー",
    # Add more replacements as needed
}

# Apply replacements
for old, new in replacements.items():
    content = content.replace(old, new)

# Remove empty columns
content = re.sub(r',,{2,}', '', content)

# Save processed content
with open("UTF-2W101-Replace済-本体-USB.csv", "w", encoding='UTF-8') as f:
    f.write(content)



```

### Key Improvements:

1. **Organization**: Grouped related tasks together (e.g., path definitions, user input handling).
2. **Error Handling**: Added error handling for user input.
3. **Efficiency**: Used a dictionary for replacements to make it easier to manage.
4. **Readability**: Simplified and cleaned up the code for better readability.

Feel free to adjust the replacements dictionary with any additional items you need!


はたして・・・

時は元禄
明治維新

いちねん くらいかけて

こつこつ

作成した

pythonのぷろぐらむ

全文 コピペして

「すっきりりさせて」

こんな無謀な ことが
できるわけないと

思ってい居たが

あっさり

回答した

恐るべし

chatGPT