forked from Imgur/imgurpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.py
More file actions
83 lines (66 loc) · 2.16 KB
/
format.py
File metadata and controls
83 lines (66 loc) · 2.16 KB
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
from ..helpers import Comment
from ..helpers import GalleryAlbum
from ..helpers import GalleryImage
from ..helpers import Notification
def build_comment_tree(children):
children_objects = []
for child in children:
to_insert = Comment(child)
to_insert.children = build_comment_tree(to_insert.children)
children_objects.append(to_insert)
return children_objects
def format_comment_tree(response):
if isinstance(response, list):
result = []
for comment in response:
formatted = Comment(comment)
formatted.children = build_comment_tree(comment['children'])
result.append(formatted)
else:
result = Comment(response)
result.children = build_comment_tree(response['children'])
return result
def build_gallery_images_and_albums(response):
if isinstance(response, list):
result = []
for item in response:
if item['is_album']:
result.append(GalleryAlbum(item))
else:
result.append(GalleryImage(item))
else:
if response['is_album']:
result = GalleryAlbum(response)
else:
result = GalleryImage(response)
return result
def build_notifications(response):
result = {
'replies': [],
'messages': [Notification(
item['id'],
item['account_id'],
item['viewed'],
item['content']
) for item in response['messages']]
}
for item in response['replies']:
notification = Notification(
item['id'],
item['account_id'],
item['viewed'],
item['content']
)
notification.content = format_comment_tree(item['content'])
result['replies'].append(notification)
return result
def build_notification(item):
notification = Notification(
item['id'],
item['account_id'],
item['viewed'],
item['content']
)
if 'comment' in notification.content:
notification.content = format_comment_tree(item['content'])
return notification