LoginSignup
1
1

More than 5 years have passed since last update.

Amazon未出荷レポート→クリックポストCSV変換

Last updated at Posted at 2018-02-09

動機

クリックポストのCSVを作るのが手作業で、くっそメンドクサイ。
手を抜きたい。

概要

Amazon未出荷レポートを、スクリプトにドラッグ&ドロップすれば、クリックポストCSVの形式に自動変換してくれるスクリプト。

未改良点:自分用のため、敬称「様」、内容品「書籍」が固定。

Python3.6.1

スクリプト convert_addr.py

# coding: UTF-8

import sys
import csv

from time import sleep

if len(sys.argv) != 2:
    print('usage: drop input_file to convert_addr.py')
    sleep(3.0)
    sys.exit()

input_file = sys.argv[1]

data = []

with open(input_file) as f:
    reader = csv.reader(f)
    for row in reader:
        data.append(row[0].split('\t'))

post_list = []
name_list = []
adr1_list = []
adr2_list = []
adr3_list = []
adr4_list = []

### SETTING ###
NAME_COL = 16
POST_COL = 22
ADR1_COL = 21
ADR2_COL = 17
ADR3_COL = 18
ADR4_COL = 19
###############

for x in data:
    name_list.append(x[NAME_COL])
    post_list.append(x[POST_COL])
    adr1_list.append(x[ADR1_COL])
    adr2_list.append(x[ADR2_COL])
    adr3_list.append(x[ADR3_COL])
    adr4_list.append(x[ADR4_COL])

post_list[0] = 'お届け先郵便番号'
name_list[0] = 'お届け先氏名'
dear = 'お届け先敬称'
adr1_list[0] = 'お届け先住所1行目'
adr2_list[0] = 'お届け先住所2行目'
adr3_list[0] = 'お届け先住所3行目'
adr4_list[0] = 'お届け先住所4行目'
cont = '内容品'

with open('out.csv', 'w', newline='') as f:
    write = csv.writer(f)

    write.writerow([post_list[0], name_list[0], dear, adr1_list[0], adr2_list[0], adr3_list[0], adr4_list[0], cont])

    i = 1
    while i < len(name_list):
        write.writerow([post_list[i], name_list[i], '様', adr1_list[i], adr2_list[i], adr3_list[i], adr4_list[i], '書籍'])
        i += 1

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1