Created
April 17, 2022 15:04
-
-
Save sasasin/568286332ae4ee0ee9beff20534f7e7d to your computer and use it in GitHub Desktop.
ブクログに登録しまくるpythonスクリプト
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
import os | |
import sys | |
import time | |
import requests | |
# how to install: | |
# wget ....(this script) | |
# pip3 install requests | |
# | |
# how to run: | |
# export BOOKLOG_ACCOUNT=xxxxxxxxxxx | |
# export BOOKLOG_PASSWORD=yyyyyyyyyyyyy | |
# cat ASIN.txt | xargs python3 booklog_add_books.py | |
# ブクログのアカウント情報 | |
ACCOUNT = os.environ['BOOKLOG_ACCOUNT'] | |
PASSWORD = os.environ['BOOKLOG_PASSWORD'] | |
# ブクログのまとめて登録ページは、この冊数ずつしか登録できない | |
MAX_BOOKS = 50 | |
def booklog_add_books(): | |
# コマンドライン引数に来たASINを、MAX_BOOKS 冊ずつの配列にバラす | |
# sys.argv[0] にはこのスクリプトファイル名が入ってるので削る | |
sys.argv.pop(0) | |
ASINS=[sys.argv[i].strip() for i in range(0, len(sys.argv))] | |
ASINS_CHUNK=[ASINS[i:i + MAX_BOOKS] for i in range(0, len(ASINS), MAX_BOOKS)] | |
with requests.Session() as session: | |
session.cookies.clear_session_cookies() | |
booklog_login(session) | |
for asins in ASINS_CHUNK: | |
booklog_input(session, asins) | |
time.sleep(30) | |
# booklog にログイン | |
def booklog_login(session): | |
LOGIN_URL = 'https://booklog.jp/login' | |
data = { | |
"account" : ACCOUNT, | |
"password": PASSWORD, | |
"service" : "booklog", | |
"ref" : "" | |
} | |
header = { | |
"Referer" : LOGIN_URL | |
} | |
response = session.post(LOGIN_URL, data=data, headers=header) | |
# まとめて登録ページ | |
def booklog_input(session, asins): | |
INPUT_URL = 'https://booklog.jp/input' | |
data = { | |
"isbns" : "\n".join(asins), | |
"category_id" : "0", # カテゴリなし | |
"status" : "4", # 積読 | |
"tags" : "" | |
} | |
header = { | |
"Referer" : INPUT_URL | |
} | |
response = session.post(INPUT_URL, data=data, headers=header) | |
if __name__ == '__main__': | |
booklog_add_books() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment