-
Notifications
You must be signed in to change notification settings - Fork 1
/
grab_supernote_images.py
executable file
·69 lines (53 loc) · 1.77 KB
/
grab_supernote_images.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
#!/usr/bin/env python3
import json
import os
import sys
class ContentFile:
stream = None
content = None
def __init__(self, stream):
self.stream = stream
self.content = json.loads(self.stream.read())
def generate_img_names(file):
result = ''
wrapper = 'http://s3.amazonaws.com/appendixjournal-images' + \
'/images/attachments{}\n'
for key in file.content['supernotes'].keys():
paragraph = file.content['supernotes'][key]
if 'image' in paragraph:
thumbnail_flag = len(paragraph['image']) > 1
for image in paragraph['image']:
result += wrapper.format(
image['url-format'].replace('***', 'medium'))
result += wrapper.format(
image['url-format'].replace('***', 'large'))
if thumbnail_flag:
result += wrapper.format(
image['url-format'].replace('***', 'thumbnail'))
return result
if __name__ == '__main__':
content_files = []
skipped_names = [
'contributors', 'cover.jpg', 'bundle.json',
'cover-chapter-1.jpg', 'cover-chapter-2.jpg',
'cover-chapter-3.jpg']
volume = None
number = None
for idx, arg in enumerate(sys.argv):
if idx == 0:
pass
elif idx == 1:
volume = arg
elif idx == 2:
number = arg
else:
name = arg.split('/')[-1]
if name not in skipped_names:
content_files.append(ContentFile(open(arg)))
current_directory = os.getcwd()
result = ''
for file in content_files:
os.chdir(current_directory)
if 'supernotes' in file.content:
result += generate_img_names(file)
print(result)