[kemonoparty] add 'revision_index' metadata field (#4727)
This commit is contained in:
@@ -219,7 +219,14 @@ class KemonopartyExtractor(Extractor):
|
|||||||
|
|
||||||
@memcache(keyarg=1)
|
@memcache(keyarg=1)
|
||||||
def _post_revisions(self, url):
|
def _post_revisions(self, url):
|
||||||
return self.request(url + "/revisions").json()
|
revs = self.request(url + "/revisions").json()
|
||||||
|
|
||||||
|
idx = len(revs)
|
||||||
|
for rev in revs:
|
||||||
|
rev["revision_index"] = idx
|
||||||
|
idx -= 1
|
||||||
|
|
||||||
|
return revs
|
||||||
|
|
||||||
|
|
||||||
def _validate(response):
|
def _validate(response):
|
||||||
@@ -253,13 +260,15 @@ class KemonopartyUserExtractor(KemonopartyExtractor):
|
|||||||
if revisions:
|
if revisions:
|
||||||
for post in posts:
|
for post in posts:
|
||||||
post["revision_id"] = 0
|
post["revision_id"] = 0
|
||||||
yield post
|
|
||||||
post_url = "{}/post/{}".format(self.api_url, post["id"])
|
post_url = "{}/post/{}".format(self.api_url, post["id"])
|
||||||
try:
|
try:
|
||||||
revs = self._post_revisions(post_url)
|
revs = self._post_revisions(post_url)
|
||||||
except exception.HttpError:
|
except exception.HttpError:
|
||||||
pass
|
post["revision_index"] = 1
|
||||||
|
yield post
|
||||||
else:
|
else:
|
||||||
|
post["revision_index"] = len(revs) + 1
|
||||||
|
yield post
|
||||||
yield from revs
|
yield from revs
|
||||||
else:
|
else:
|
||||||
yield from posts
|
yield from posts
|
||||||
@@ -292,8 +301,9 @@ class KemonopartyPostExtractor(KemonopartyExtractor):
|
|||||||
try:
|
try:
|
||||||
revs = self._post_revisions(self.api_url)
|
revs = self._post_revisions(self.api_url)
|
||||||
except exception.HttpError:
|
except exception.HttpError:
|
||||||
pass
|
post["revision_index"] = 1
|
||||||
else:
|
else:
|
||||||
|
post["revision_index"] = len(revs) + 1
|
||||||
return itertools.chain((post,), revs)
|
return itertools.chain((post,), revs)
|
||||||
return (post,)
|
return (post,)
|
||||||
|
|
||||||
|
|||||||
@@ -169,13 +169,14 @@ __tests__ = (
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://kemono.party/patreon/user/3161935/post/68231671/revision/134996",
|
"#url" : "https://kemono.su/patreon/user/3161935/post/68231671/revision/142470",
|
||||||
"#comment" : "revisions (#4498)",
|
"#comment" : "revisions (#4498)",
|
||||||
"#category": ("", "kemonoparty", "patreon"),
|
"#category": ("", "kemonoparty", "patreon"),
|
||||||
"#class" : kemonoparty.KemonopartyPostExtractor,
|
"#class" : kemonoparty.KemonopartyPostExtractor,
|
||||||
"#urls" : "https://kemono.party/data/88/52/88521f71822dfa2f42df3beba319ea4fceda2a2d6dc59da0276a75238f743f86.jpg",
|
"#urls" : "https://kemono.su/data/88/52/88521f71822dfa2f42df3beba319ea4fceda2a2d6dc59da0276a75238f743f86.jpg",
|
||||||
|
|
||||||
"revision_id": 134996,
|
"revision_id": 142470,
|
||||||
|
"revision_index": 2,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -188,6 +189,7 @@ __tests__ = (
|
|||||||
"#archive" : False,
|
"#archive" : False,
|
||||||
|
|
||||||
"revision_id": range(134996, 3052965),
|
"revision_id": range(134996, 3052965),
|
||||||
|
"revision_index": range(1, 9),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user