Created
November 23, 2020 14:17
-
-
Save LinusCDE/56ecba353b2bba0e90c7b0c72b702cdd to your computer and use it in GitHub Desktop.
Script to integrate PDF into Xochitl (on-device)
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
#!/usr/bin/env python3 | |
import json | |
from os import system, path | |
from shlex import quote | |
from sys import argv, stderr | |
from time import time | |
from uuid import uuid4 | |
DOC_DIR = '/home/root/.local/share/remarkable/xochitl/' | |
#DOC_DIR = '' | |
def integratePdf(filename): | |
if not filename.endswith('.pdf'): | |
print("Isn't pdf!", file=stderr) | |
exit(1) | |
return | |
meta = { | |
'deleted': False, | |
'lastModified': str(int(time() * 1000)), | |
'metadatamodified': False, | |
'modified': False, | |
'parent' : '', # Root dir | |
'pinned': False, | |
'synced': False, | |
'type': 'DocumentType', # Is pdf | |
'version': 1, | |
'visibleName': path.basename(filename) | |
} | |
content = { | |
'extraMetadata': {}, | |
'fileType': 'pdf', | |
'fontName': '', | |
'lastOpenedPage': 0, | |
'lineHeight': -1, | |
'margins': '100', | |
'pageCount': 1, | |
'textScale': 1, | |
'transform': { | |
'm11': 1, | |
'm12': 0, | |
'm13': 0, | |
'm21': 0, | |
'm22': 0, | |
'm23': 0, | |
'm31': 0, | |
'm32': 0, | |
'm33': 1 | |
} | |
} | |
uuid = str(uuid4()) | |
with open(DOC_DIR + uuid + '.metadata', 'w') as fp: | |
json.dump(meta, fp, indent=4) | |
with open(DOC_DIR + uuid + '.content', 'w') as fp: | |
json.dump(content, fp, indent=4) | |
system('mv %s %s' % (quote(filename), quote(DOC_DIR + uuid + '.pdf'))) | |
return uuid | |
if __name__ == '__main__': | |
if len(argv) != 2: | |
print('Usage: %s <Document>' % argv[0], file=stderr) | |
exit(1) | |
filename = argv[1] | |
if filename.endswith('.pdf'): | |
uuid = integratePdf(filename) | |
print('Done. Uuid is %s' % uuid) | |
else: | |
print('Filetype not supported.', file=stderr) | |
exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment