Skip to content

Instantly share code, notes, and snippets.

@jurgjn
Last active May 8, 2020 13:58
Show Gist options
  • Save jurgjn/306b0439d7af8ec528ef9c4f3fc4d708 to your computer and use it in GitHub Desktop.
Save jurgjn/306b0439d7af8ec528ef9c4f3fc4d708 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import collections
import csv
import itertools
import logging
import json
import os
import uuid
import math
import shutil
import sys
from glob import glob
from pprint import pprint
_inp = sys.argv[1]
assert os.path.isfile(_inp)
_uuid = uuid.uuid1()
print(_inp)
print(_uuid)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134/
# - .json and .rm files of annotations
_dir = '%(_uuid)s' % locals()
os.makedirs(_dir)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.cache/
# - pre-rendered .png-s of a subset of pages
_cache = '%(_uuid)s.cache' % locals()
os.makedirs(_cache)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.content
# - json with a bunch of document-specific settings (e.g. original file name)
_content = '%(_uuid)s.content' % locals()
_content_json = collections.OrderedDict([
('extraMetadata', {}),
('fileType', 'pdf'),
('fontName', ''),
('lastOpenedPage', 0),
('lineHeight', -1),
('margins', 100),
('orientation', u'portrait'),
('pageCount', 1),
('textScale', 1),
('transform', collections.OrderedDict([
('m11', 1),
('m12', 0),
('m13', 0),
('m21', 0),
('m22', 1),
('m23', 0),
('m31', 0),
('m32', 0),
('m33', 1),
])),
])
with open(_content, 'w') as f:
json.dump(_content_json, f, indent=4)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.highlights/
# - empty directory
_highlights = '%(_uuid)s.highlights' % locals()
os.makedirs(_highlights)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.pdf
_pdf = '%(_uuid)s.pdf' % locals()
shutil.copy(_inp, _pdf)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.metadata
# - json with a bunch of document-specific settings
# Ref: https://github.com/adaerr/reMarkableScripts/blob/master/pdf2remarkable.sh#L86-L101
_metadata = '%(_uuid)s.metadata' % locals()
_contents = collections.OrderedDict([
('deleted', False),
('lastModified', '1569581622447'),
('metadatamodified', False),
('modified', False),
('parent', ''),
('pinned', False),
('synced', False),
('type', 'DocumentType'),
('version', 0),
('visibleName', _inp),
])
with open(_metadata, 'w') as f:
json.dump(_contents, f, indent=4)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.pagedata
# - Template name or Blank for PDF-s
_pagedata = '%(_uuid)s.pagedata' % locals()
open(_pagedata, 'w').close()
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.textconversion/
# - Text conversion
_textconversion = '%(_uuid)s.textconversion' % locals()
os.makedirs(_textconversion)
# 0c146cf6-4dee-4c7c-8687-7e40f4759134.thumbnails/
# - .jpg files, pre-rendered, small-ish?
# - These seem to be auto-generated by remarkable...
_thumbnails = '%(_uuid)s.thumbnails' % locals()
os.makedirs(_thumbnails)
# Assumes ssh public key auth has been set up
print('scp -r %(_uuid)s* [email protected]:.local/share/remarkable/xochitl/' % locals())
print('ssh [email protected] systemctl restart xochitl')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment