-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremarkable_migrate_papers.py
168 lines (124 loc) · 4.84 KB
/
remarkable_migrate_papers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import pprint
import os
from rmcl import Item, Document, Folder, invalidate_cache_s
import trio
# Script to move PDFs to Remarkable while preserving the directory structure
pp = pprint.PrettyPrinter(indent=4)
relative_path = "/Users/xxxxxxx/Desktop"
#papers_dir = "papers/discretization"
papers_dir = "papers"
abs_dir = os.path.join(relative_path,papers_dir)
TRASH_ID = 'trash'
# clear cache
invalidate_cache_s()
async def list_files():
root = await Item.get_by_id('') # The root folder has ID of empty string
for child in root.children:
if isinstance(child, Folder):
print(f"folder: {child.name}")
pp.pprint(child.__dict__)
#if child.name in ['foo', 'testpath', 'SynologyDrive', 'papers']:
# print("child recognized")
# await child.delete()
elif isinstance(child, Document): # The only other possibility
print(f"{await child.type()}: {child.name}")
print(child.id)
pp.pprint(child.__dict__)
# move item to trash by updating metadata
#child.parent = TRASH_ID
#await child.update_metadata()
await child.delete()
async def list_dir(folder):
root = await Folder.get_by_id(folder.id)
parentName = root.name
sub_dirs = []
print(f"{parentName}: ")
for child in root.children:
if isinstance(child, Folder):
#parentItem = await Item.get_by_id(child.parent)
#parentName = parentItem.name
sub_dirs.append(child)
#print(f" {child.name}/")
print(f" {child.name}/")
#print(f"folder: {child.name}")
#print(f"{child.parent} -> {child.name}")
#pp.pprint(child.__dict__)
#await list_dir(child)
elif isinstance(child, Document): # The only other possibility
print(f" {child.name}, {await child.type()}")
#print(f"{await child.type()}, {child.name}")
#print(f" {child.name} ({await child.type()})")
#pp.pprint(child.__dict__)
#await child.delete()
for child in sub_dirs:
await list_dir(child)
#for child in sub_dirs:
# if child.name != ".trash":
# await child.delete()
async def list_nested_files():
root = await Item.get_by_id('') # The root folder has ID of empty string
sub_dirs = []
for child in root.children:
if isinstance(child, Folder):
#parentItem = await Item.get_by_id(child.parent)
#parentName = parentItem.name
sub_dirs.append(child)
print(f" {child.name}/")
#pp.pprint(child.__dict__)
#if child.name in ['foo', 'testpath', 'SynologyDrive', 'papers']:
# print("child recognized")
# await child.delete()
elif isinstance(child, Document): # The only other possibility
print(f" {child.name}, {await child.type()}")
#print(child.id)
#pp.pprint(child.__dict__)
# move item to trash by updating metadata
#child.parent = TRASH_ID
#await child.update_metadata()
#await child.delete()
for child in sub_dirs:
await list_dir(child)
#for child in sub_dirs:
# if child.name != ".trash":
# await child.delete()
#trio.run(list_files)
#trio.run(list_nested_files)
def migrate_dir(folder):
for child in folder.children:
if isinstance(child, Folder):
#parentItem = await Item.get_by_id(child.parent)
#parentName = parentItem.name
sub_dirs.append(child)
print(f" {child.name}/")
#pp.pprint(child.__dict__)
#if child.name in ['foo', 'testpath', 'SynologyDrive', 'papers']:
# print("child recognized")
# await child.delete()
elif isinstance(child, Document): # The only other possibility
print(f" {child.name}, {child.type()}")
#print(child.id)
#pp.pprint(child.__dict__)
# move item to trash by updating metadata
#child.parent = TRASH_ID
#await child.update_metadata()
#await child.delete()
#for child in sub_dirs:
# await list_dir(child)
# traverse root directory, and list directories as dirs and files as files
for root, dirs, files in os.walk(abs_dir):
print()
rel_path = os.path.relpath(root, relative_path)
#print(rel_path)
rpath = rel_path.split(os.sep)
print(root)
path = root.split(os.sep)
#for dirpath in dirs:
# print(dirpath)
#print("mkdir " + rel_path)
for file in files:
print("file:", file)
#file_path = os.path.join(root, file)
#if file[0] != '.':
# print("upload " + file_path + " " + rel_path)
for dir in dirs:
print("dir:", dir)