Created
July 2, 2024 02:57
-
-
Save ajorg/0a73d7ec8a4df62705deeccd4d9ff488 to your computer and use it in GitHub Desktop.
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
# Author: Andrew Jorgensen | |
# SPDX-License-Identifier: MIT-0 | |
"""Download all files from your reMarkable as PDFs | |
Uses the local web interface (via USB Ethernet). | |
""" | |
from json import dumps, load | |
from os import makedirs | |
from os.path import exists, join | |
from sys import stdout | |
from urllib.request import urlopen | |
BASE_URL = "http://10.11.99.1" | |
DOCUMENTS_URL = BASE_URL + "/documents/" | |
DOWNLOAD_URL = BASE_URL + "/download/" | |
def download(guid, parent, name): | |
name = name.replace("/", "_") | |
file = join(parent, name + ".pdf") | |
print(file) | |
url = DOWNLOAD_URL + guid + "/pdf" | |
print(url) | |
if exists(file): | |
return | |
if parent: | |
makedirs(parent, exist_ok=True) | |
with open(file, "wb") as pdf_f: | |
with urlopen(url) as download_u: | |
while data := download_u.read(4096): | |
pdf_f.write(data) | |
def get_documents(guid="", parent=""): | |
with urlopen(DOCUMENTS_URL + guid) as documents_u: | |
documents = load(documents_u) | |
for document in documents: | |
name = document.get("VissibleName") | |
if document.get("Type") == "DocumentType": | |
download(document.get("ID"), parent, name) | |
elif document.get("Type") == "CollectionType": | |
get_documents(document.get("ID"), join(parent, name)) | |
get_documents() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment