Repository navigation
Expand file tree
/
Copy pathtypes.py
More file actions
315 lines (277 loc) · 10.3 KB
/
Copy pathtypes.py
File metadata and controls
315 lines (277 loc) · 10.3 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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import json
class JsonDeserializable(object):
@staticmethod
def check_json(json_type):
if type(json_type) == dict:
return json_type
elif type(json_type) == str:
return json.loads(json_type)
else:
raise ValueError('json_type must be a json dict or string.')
class Error(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
code = obj['code']
message = obj['message']
return cls(code, message)
def __init__(self, code: int, message: str):
self.code = code
self.message = message
class Response(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
error = None
data = None
if 'error' in obj:
error = Error.de_json(obj['error'])
if 'data' in obj:
data = obj['data']
success = obj['success']
return cls(success, data=data, error=error)
def __init__(self, success: int, data=None, error=None):
if data:
self.data = data
if error:
self.error = error
self.success = success
class Range(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
start = obj['start']
stop = obj['stop']
return cls(start, stop)
def __init__(self, start: int, stop: int):
self.start = start
self.stop = stop
class Mention(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
account_id = obj['accountID']
username = obj['username']
text = obj['text']
range = Range.de_json(obj['range'])
byte_range = Range.de_json(obj['byteRange'])
return cls(account_id, username, text, range, byte_range)
def __init__(self, account_id: str, username: str,
text: str, range: Range, byte_range: Range):
self.account_id = account_id
self.username = username
self.text = text
self.range = range
self.byte_range = byte_range
class Comment(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
id = obj['id']
post_id = obj['postID']
author_id = obj['authorID']
body = obj['body']
mentions = [
Mention.de_json(mention) for mention in obj['mentions']
]
date = obj['date']
options = {}
if 'accounts' in obj:
options['accounts'] = {
account: Account.de_json(obj['accounts'][account])
for account in obj['accounts'].keys()
}
return cls(id, post_id, author_id, body, mentions, date, options)
def __init__(self, id: str, post_id: str, author_id: str,
body: str, mentions: list, date: int, options: dict):
self.id = id
self.post_id = post_id
self.author_id = author_id
self.body = body
self.mentions = mentions
self.date = date
for key in options:
setattr(self, key, options[key])
class Post(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
id = obj['id']
type = obj['type']
author_id = obj['authorID']
caption = obj['caption']
allow_curation = obj['allowCuration']
allow_remix = obj['allowRemix']
mentions = [
Mention.de_json(mention) for mention in obj['mentions']
]
date = obj['date']
video_src = obj['videoSrc']
thumb_src = obj['thumbSrc']
comment_count = obj['commentCount']
like_count = obj['likeCount']
liked_by_me = obj['likedByMe']
loop_count = obj['loopCount']
rebyted_by_me = obj['rebytedByMe']
options = {}
if 'category' in obj:
options['category'] = obj['category']
if 'comments' in obj:
options['comments'] = [
Comment.de_json(comment) for comment in obj['comments']
]
return cls(id, type, author_id, caption,
allow_curation, allow_remix,
mentions, date, video_src, thumb_src,
comment_count, like_count, liked_by_me,
loop_count, rebyted_by_me, options)
def __init__(self, id: str, type: int, author_id: str, caption: str,
allow_curation: bool, allow_remix: bool,
mentions: list, date: int, video_src: str, thumb_src: str,
comment_count: int, like_count: int, liked_by_me: bool,
loop_count: int, rebyted_by_me: bool, options: dict):
self.id = id
self.type = type
self.author_id = author_id
self.caption = caption
self.allow_curation = allow_curation
self.allow_remix = allow_remix
self.mentions = mentions
self.date = date
self.video_src = video_src
self.thumb_src = thumb_src
self.comment_count = comment_count
self.like_count = like_count
self.liked_by_me = liked_by_me
self.loop_count = loop_count
self.rebyted_by_me = rebyted_by_me
for key in options:
setattr(self, key, options[key])
class Feed(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
posts = [
Post.de_json(post) for post in obj['data']['posts']
]
success = obj['success']
options = {}
if 'cursor' in obj['data']:
options['cursor'] = obj['data']['cursor']
if 'accounts' in obj['data']:
options['accounts'] = {
account: Account.de_json(obj['data']['accounts'][account])
for account in obj['data']['accounts'].keys()
}
return Response(success, cls(posts, options))
def __init__(self, posts: list, options: dict):
self.posts = posts
for key in options:
setattr(self, key, options[key])
class Color(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
background = obj['background']
foreground = obj['foreground']
id = obj['id']
return cls(background, foreground, id)
def __init__(self, background: str, foreground: str, id: int):
self.background = background
self.foreground = foreground
self.id = id
class Colors(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
colors = [
Color.de_json(color) for color in obj['colors']
]
return cls(colors)
def __init__(self, colors: list):
self.colors = colors
class Account(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
background_color = obj['backgroundColor']
follower_count = obj['followerCount']
following_count = obj['followingCount']
foreground_color = obj['foregroundColor']
id = obj['id']
is_channel = obj['isChannel']
loop_count = obj['loopCount']
loops_consumed_count = obj['loopsConsumedCount']
registration_date = obj['registrationDate']
username = obj['username']
options = {}
if 'avatarURL' in obj:
options['avatar_url'] = obj['avatarURL']
if 'isDeactivated' in obj:
options['is_deactivated'] = obj['isDeactivated']
if 'isRegistered' in obj:
options['is_registered'] = obj['isRegistered']
if 'isBlocked' in obj:
options['is_blocked'] = obj['isBlocked']
if 'bio' in obj:
options['bio'] = obj['bio']
if 'isFollowing' in obj:
options['is_following'] = obj['isFollowing']
if 'isFollowed' in obj:
options['is_followed'] = obj['isFollowed']
if 'isSuspended' in obj:
options['is_suspended'] = obj['isSuspended']
if 'displayName' in obj:
options['display_name'] = obj['displayName']
return cls(background_color,
follower_count, following_count,
foreground_color, id, is_channel,
loop_count, loops_consumed_count,
registration_date, username, options)
def __init__(self, background_color: str,
follower_count: int, following_count: int,
foreground_color: str, id: str, is_channel: bool,
loop_count: int, loops_consumed_count: int,
registration_date: int, username: str, options: dict):
self.background_color = background_color
self.follower_count = follower_count
self.following_count = following_count
self.foreground_color = foreground_color
self.id = id
self.is_channel = is_channel
self.loop_count = loop_count
self.loops_consumed_count = loops_consumed_count
self.registration_date = registration_date
self.username = username
for key in options:
setattr(self, key, options[key])
class LoopCounter(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
id = obj['postID']
loop_count = obj['loopCount']
return cls(id, loop_count)
def __init__(self, id: str, loop_count: int):
self.id = id
self.loop_count = loop_count
class Rebyte(JsonDeserializable):
@classmethod
def de_json(cls, json_type: dict):
obj = cls.check_json(json_type)
accounts = {
account: Account.de_json(obj['accounts'][account])
for account in obj['accounts'].keys()
}
author_id = obj['authorID']
date = obj['date']
id = obj['id']
post = Post.de_json(obj['post'])
return cls(accounts, author_id, date, id, post)
def __init__(self, accounts: dict, author_id: str,
date: int, id: str, post: Post):
self.accounts = accounts
self.author_id = author_id
self.date = date
self.id = id
self.post = post