BOOTHの宛名印刷用CSVをクリックポストのまとめ申込CSVに変換するやつ
#! /usr/local/bin/python3 | |
# -*- coding:utf8 -*- | |
# BOOTH2clickpost | |
# Author: mzsm | |
# License: NYSL <http://www.kmonos.net/nysl/> | |
import csv | |
import re | |
from optparse import OptionParser | |
def main(): | |
usage = 'usage: %prog [options] sourcefile' | |
parser = OptionParser(usage) | |
parser.add_option('-c', '--content', dest='content', | |
help='内容物', default='書籍') | |
(options, args) = parser.parse_args() | |
if len(args) < 1: | |
print('変換元のCSVファイルを指定してください') | |
exit(1) | |
input_file = args[0] | |
export_file = re.sub(r'(\..+?)$', r'_export\1', input_file) | |
try: | |
f = open(input_file) | |
except FileNotFoundError: | |
print('変換元のCSVファイルが存在しません') | |
exit(1) | |
of = open(export_file, 'w', encoding='cp932') | |
writer = csv.writer(of) | |
header = [ | |
'お届け先郵便番号', 'お届け先氏名', 'お届け先敬称', | |
'お届け先住所1行目', 'お届け先住所2行目', 'お届け先住所3行目', 'お届け先住所4行目', '内容品' | |
] | |
writer.writerow(header) | |
for idx, input_row in enumerate(csv.reader(f)): | |
if not idx: | |
continue | |
output_row = [input_row[8], input_row[12], '様'] | |
output_row.extend(input_row[9:12]) | |
output_row.append('') | |
output_row.append(options.content) | |
writer.writerow(output_row) | |
of.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
mzsm commentedOct 25, 2017
使い方
$ chmod -x booth2clickpost.py
$ booth2clickpost.py ~/Downloads/booth_orders_yyyymmddhhmmss.csv
_export
が付いたファイル名でCSVが出力される~/Downloads/booth_orders_yyyymmddhhmmss_export.csv
に出力されるいろいろ
-c 内容物
または--content=内容物
で変更できます。