Last active
October 10, 2022 13:14
-
-
Save mzsm/842f3b7a6569c52e4e9e6c00de8ec9c6 to your computer and use it in GitHub Desktop.
BOOTHの宛名印刷用CSVをクリックポストのまとめ申込CSVに変換するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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
使い方
$ chmod -x booth2clickpost.py
$ booth2clickpost.py ~/Downloads/booth_orders_yyyymmddhhmmss.csv
_export
が付いたファイル名でCSVが出力される~/Downloads/booth_orders_yyyymmddhhmmss_export.csv
に出力されるいろいろ
-c 内容物
または--content=内容物
で変更できます。