[fanbox] handle KeyError for no longer existing plans (#5759)

return the plan of the next higher tier instead
pull/5774/head
Mike Fährmann 3 months ago
parent 11421cf940
commit 8452d04a33
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -113,7 +113,12 @@ class FanboxExtractor(Extractor):
post["user"] = self._get_user_data(post["creatorId"]) post["user"] = self._get_user_data(post["creatorId"])
if self._meta_plan: if self._meta_plan:
plans = self._get_plan_data(post["creatorId"]) plans = self._get_plan_data(post["creatorId"])
post["plan"] = plans[post["feeRequired"]] fee = post["feeRequired"]
try:
post["plan"] = plans[fee]
except KeyError:
post["plan"] = plans[fee] = min(
p for p in plans.values() if p["fee"] >= fee)
return content_body, post return content_body, post

@ -123,6 +123,22 @@ __tests__ = (
}, },
}, },
{
"#url" : "https://saki9184.fanbox.cc/posts/7754760",
"#comment" : "missing plan for exact 'feeRequired' value (#5759)",
"#category": ("", "fanbox", "post"),
"#class" : fanbox.FanboxPostExtractor,
"#options" : {"metadata": "plan"},
"feeRequired": 300,
"plan" : {
"creatorId": "saki9184",
"fee" : 350,
"id" : "414274",
"title" : "涼宮ハルヒの憂鬱",
},
},
{ {
"#url" : "https://mochirong.fanbox.cc/posts/3746116", "#url" : "https://mochirong.fanbox.cc/posts/3746116",
"#comment" : "imageMap file order (#2718)", "#comment" : "imageMap file order (#2718)",

Loading…
Cancel
Save