Skip to content

Commit

Permalink
fix 订阅统计清理
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed May 7, 2024
1 parent 4a3a348 commit bd348f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/api/endpoints/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,12 @@ def delete_subscribe(
"""
删除订阅信息
"""
Subscribe.delete(db, subscribe_id)
subscribe = Subscribe.get(db, subscribe_id)
if subscribe:
subscribe.delete(db, subscribe_id)
# 统计订阅
SubscribeHelper().sub_done_async({
"tmdbid": subscribe.tmdbid,
"doubanid": subscribe.doubanid
})
return schemas.Response(success=True)
10 changes: 10 additions & 0 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,11 @@ def __finish_subscribe(self, subscribe: Subscribe, mediainfo: MediaInfo,
"subscribe_info": subscribe.to_dict(),
"mediainfo": mediainfo.to_dict(),
})
# 统计订阅
self.subscribehelper.sub_done_async({
"tmdbid": mediainfo.tmdb_id,
"doubanid": mediainfo.douban_id
})

def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None):
"""
Expand Down Expand Up @@ -920,6 +925,11 @@ def remote_delete(self, arg_str: str, channel: MessageChannel, userid: Union[str
return
# 删除订阅
self.subscribeoper.delete(subscribe_id)
# 统计订阅
self.subscribehelper.sub_done_async({
"tmdbid": subscribe.tmdbid,
"doubanid": subscribe.doubanid
})
# 重新发送消息
self.remote_list(channel, userid)

Expand Down
23 changes: 23 additions & 0 deletions app/helper/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SubscribeHelper(metaclass=Singleton):

_sub_reg = "https://movie-pilot.org/subscribe/add"

_sub_done = "https://movie-pilot.org/subscribe/done"

_sub_report = "https://movie-pilot.org/subscribe/report"

_sub_statistic = "https://movie-pilot.org/subscribe/statistic"
Expand Down Expand Up @@ -58,6 +60,19 @@ def sub_reg(self, sub: dict) -> bool:
return True
return False

def sub_done(self, sub: dict) -> bool:
"""
完成订阅统计
"""
if not settings.SUBSCRIBE_STATISTIC_SHARE:
return False
res = RequestUtils(timeout=5, headers={
"Content-Type": "application/json"
}).post_res(self._sub_done, json=sub)
if res and res.status_code == 200:
return True
return False

def sub_reg_async(self, sub: dict) -> bool:
"""
异步新增订阅统计
Expand All @@ -66,6 +81,14 @@ def sub_reg_async(self, sub: dict) -> bool:
Thread(target=self.sub_reg, args=(sub,)).start()
return True

def sub_done_async(self, sub: dict) -> bool:
"""
异步完成订阅统计
"""
# 开新线程处理
Thread(target=self.sub_done, args=(sub,)).start()
return True

def sub_report(self) -> bool:
"""
上报存量订阅统计
Expand Down

0 comments on commit bd348f1

Please sign in to comment.