-
Notifications
You must be signed in to change notification settings - Fork 2
/
post.py
208 lines (172 loc) · 5.34 KB
/
post.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
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
from datetime import datetime
class r34Post:
@staticmethod
def from_json(json):
pFileUrl = json["file_url"]
pImage = json["image"]
pHash = json["hash"]
pId = json["id"]
pScore = json["score"]
pSize = [json["width"], json["height"]]
pOwner = json["owner"]
pTags = json["tags"].split(" ")
preview = json["preview_url"]
sample = json["sample_url"] # thumbnail
change = json["change"]
directory = json["directory"]
if pFileUrl.endswith(".mp4"):
file_type = "video"
elif pFileUrl.endswith(".gif"):
file_type = "gif"
else:
file_type = "image"
return r34Post(pId, pHash, pScore, pSize, pFileUrl, pImage, preview, sample, pOwner, pTags, file_type, directory, change)
#(pId, pHash, pScore, pSize, pFileUrl, pImage, preview, sample, pOwner, pTags, img_type, directory, change)
@staticmethod
def from_xml(soup_post):
pFileUrl = soup_post["file_url"]
pImage = pFileUrl.split('/')[5]#soup_post["image"]
pHash = soup_post["md5"]
pId = soup_post["id"]
pScore = soup_post["score"]
pSize = [soup_post["width"], soup_post["height"]]
pOwner = soup_post["creator_id"]
pTags = soup_post["tags"].split(" ")
preview = soup_post["preview_url"]
sample = soup_post["sample_url"] # thumbnail
change = soup_post["change"]
#directory = soup_post["directory"]
date = datetime.strptime(soup_post["created_at"], '%a %b %d %H:%M:%S %z %Y')
if pFileUrl.endswith(".mp4"):
file_type = "video"
elif pFileUrl.endswith(".gif"):
file_type = "gif"
else:
file_type = "image"
return r34Post(pId, pHash, pScore, pSize, pFileUrl, pImage, preview, sample, pOwner, pTags, file_type, change, date)
def __init__(self, id: int, hash: str, score: int, size: list, fileurl: str, image: str, preview: str, sample: str, owner: str, tags: list, file_type: str, change: int, date: str):
self._file_type = file_type
self._video = ""
self._image = ""
if file_type == "image" or file_type == "gif":
self._image = image
elif file_type == "video":
self._video = image
self._id = id
self._hash = hash
self._score = score
self._size = size # > [WIDTH:int, HEIGHT:int]
self._fileurl = fileurl #add
#self._image = image
self._preview = preview # thumbnail
self._sample = sample
self._owner = owner
self._tags = tags # > [TAG:str, TAG:str,...]
#self._directory = directory
self._change = change
self._date = date
@property
def id(self) -> int:
"""Get id of post
Returns:
int: Id of Post
"""
return self._id
@property
def hash(self) -> str:
"""Get hash of post
Returns:
str: Hash of Post
"""
return self._hash
@property
def score(self) -> int:
"""Get score of post
Returns:
int: Score of post
"""
return self._score
@property
def size(self) -> list:
"""Get image size
Returns:
list: Returns a list of to integers (eg: [1920, 1080] > [WIDTH, HEIGHT])
"""
return self._size
@property
def fileurl(self) -> str: #add
"""Get image fileurl
Returns:
str with file url https://
"""
return self._fileurl
@property
def image(self) -> str:
"""Get post image
Returns:
list: Image url
"""
return self._image
@property
def video(self) -> str:
"""Get post video
Returns:
list: Video url
"""
return self._video
@property
def thumbnail(self) -> str:
"""Get post thumbnail
Returns:
list: Image url
"""
return self._preview
@property
def sample(self) -> str:
"""Get post sample image
Returns:
list: Image url
"""
return self._sample
@property
def owner(self) -> str:
"""Get username of post creator
Returns:
str: Name of owner
"""
return self._owner
@property
def tags(self) -> list:
"""Get tags of post
Returns:
list: String list of tags
"""
return self._tags
@property
def content_type(self) -> str:
"""Get type of post data (e.g. gif, image etc.)
Returns:
list: String of data type
"""
return self._file_type
@property
def change(self) -> int:
"""Get change unix time epoch
Returns:
int: Unix timestamp
"""
return self._change
@property
def directory(self) -> int:
"""Get directory id of post
Returns:
int: Directory id
"""
return self._directory
@property
def date(self) -> str:
"""Get date of post
Returns:
int: date of Post
"""
return self._date