Skip to content

Instantly share code, notes, and snippets.

@takemikami
Last active March 16, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takemikami/af01fdd024d7f933edf2a441f4891fb5 to your computer and use it in GitHub Desktop.
Save takemikami/af01fdd024d7f933edf2a441f4891fb5 to your computer and use it in GitHub Desktop.
Booth売上のMoneyForward会計用インポートファイル作成スクリプト
# Booth売上のMoneyForward会計用インポートファイル作成スクリプト
#
# 設定手順:
# pip install selenium
# pip install chromedriver-binary==<利用しているChromeバージョン>
# pip install beautifulsoup4
# pip install html5lib
# 実行方法:
# python booth_mf_import.py
# 実行後「booth_mf_import_年.csv」が出力されるので、MoneyForward会計の仕訳帳からインポートする
import time
import datetime
import calendar
from selenium import webdriver
import chromedriver_binary
from bs4 import BeautifulSoup
# 各種設定 - 消費税の課税事業者、補助科目の設定に応じて変更する
YEAR = 2020 # 対象年
TAX_TYPE_SALES = '対象外' # 消費税の種別(売上)
TAX_TYPE_COMMISSION = '対象外' # 消費税の種別(手数料)
URIAGE_SUBTYPE = 'Booth' # 売上高の補助科目
URIKAKE_SUBTYPE = 'ピクシブ株式会社' # 売掛金の補助科目
driver = webdriver.Chrome() # options=options)
driver.get('https://manage.booth.pm/users/sign_in')
print("Boothにログインしてからエンター押してね")
input()
print("処理を続けます")
today = datetime.datetime.today()
y = YEAR
journal_no = 0
rows = []
for m in range(1, 13):
# 月間売上・手数料の取得
sales_value_map = {}
driver.get('https://manage.booth.pm/sales/{}/{}'.format(y, m))
html = driver.page_source.encode('utf-8')
soup = BeautifulSoup(html, 'html5lib')
tpg_caption2s = soup.find_all("div", class_='u-tpg-caption2')
for tpg_caption2 in tpg_caption2s:
cells = tpg_caption2.find_all("div", class_='lo-grid-cell')
if len(cells) == 2:
title = cells[0].text
value = str(cells[1].text)
if value.startswith('¥'):
value = value.replace('¥', '').replace(',', '')
sales_value_map[title] = int(value)
if '総売上' not in sales_value_map or '手数料' not in sales_value_map:
continue
# 仕訳の作成
journal_no += 1
dt = datetime.datetime(y, m, calendar.monthrange(y, m)[1])
rows.append([
str(journal_no),
dt.strftime("%Y/%m/%d"),
'売掛金',
URIKAKE_SUBTYPE,
'対象外',
'',
sales_value_map['総売上'] - sales_value_map['手数料'],
'',
'売上高',
URIAGE_SUBTYPE,
TAX_TYPE_SALES,
'',
sales_value_map['総売上'],
'',
'Booth売上 {}年{}月'.format(y, m),
'',
'',
'',
'',
today.strftime("%Y/%m/%d"),
today.strftime("%Y/%m/%d"),
])
rows.append([
str(journal_no),
dt.strftime("%Y/%m/%d"),
'支払手数料',
'',
TAX_TYPE_COMMISSION,
'',
sales_value_map['手数料'],
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
today.strftime("%Y/%m/%d"),
today.strftime("%Y/%m/%d"),
])
# インポートファイルの出力
HEADER_COLS = ['取引No',
'取引日',
'借方勘定科目',
'借方補助科目',
'借方税区分',
'借方部門',
'借方金額(円)',
'借方税額',
'貸方勘定科目',
'貸方補助科目',
'貸方税区分',
'貸方部門',
'貸方金額(円)',
'貸方税額',
'摘要',
'仕訳メモ',
'タグ',
'MF仕訳タイプ',
'決算整理仕訳',
'作成日時',
'最終更新日時']
with open('booth_mf_import_{}.csv'.format(y), mode='w') as f:
f.write(','.join(HEADER_COLS))
f.write('\n')
for r in rows:
f.write(','.join([str(v) if v is not None else '' for v in r]))
f.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment