PythonでScrapboxにimport
Puppeteerを使えばScrapboxにボットを住まわせられることがわかったのでNodeとPuppeteerを勉強しよう
→NodeとPuppeteerを勉強してるしてる間にPuppeteerが必要なくなってたw
→Puppeteerいらないならぼく不慣れなNode使わずにPythonでできるのでは…試してみるか
→できた
code:python
import requests
from dotenv import load_dotenv
import json
import os
load_dotenv()
def write_pages(pages):
sid = os.getenv("SID")
project = os.getenv("PROJECT")
cookie = "connect.sid=" + sid
r = requests.get(API_ME, headers={"Cookie": cookie})
r.raise_for_status()
url = API_IMPORT.format(project=project)
data = json.dumps({"pages": pages})
r = requests.post(
url,
files={"import-file": data},
headers={
"Cookie": cookie,
"Accept": "application/json, text/plain, */*",
"X-CSRF-TOKEN": csrfToken,
}
)
r.raise_for_status()
def _test():
pages = [
{
"title": "Scbot Home",
}
]
write_pages(pages)