Skip to content

Commit 46fbb1f

Browse files
committed
[untag] Add untag_entry and untag_entries method, and simplify delete_tags
1 parent 1f5095d commit 46fbb1f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

feedly/api_client/data.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def tag_entries(self, entry_ids: List[str]):
7676
self._client.do_api_request(f'/v3/tags/{quote_plus(self["id"])}', method='put',
7777
data={'entryIds': [entry_id for entry_id in entry_ids]})
7878

79+
def untag_entry(self, entry_id: str):
80+
self.untag_entries([entry_id])
81+
82+
def untag_entries(self, entry_ids: List[str]):
83+
# limitation due to the url length: articles are "de-tagged" by batch of 50.
84+
for i in range(0, len(entry_ids), 50):
85+
self._client.do_api_request(
86+
f'/v3/tags/{quote_plus(self["id"])}/{",".join([quote_plus(d) for d in entry_ids[i: i+50]])}',
87+
method='DELETE',
88+
)
89+
7990
def delete_tags(self, options: StreamOptions = None):
8091
"""
8192
*** WARNING *** Non-reversible operation
@@ -86,14 +97,7 @@ def delete_tags(self, options: StreamOptions = None):
8697
:return:
8798
"""
8899
a_ids = [a["id"] for a in self.stream_contents(options)]
89-
tag_id = self._get_id()
90-
while len(a_ids) > 0:
91-
batch_size = 50 # limitation due to the url length: articles are "de-tagged" by batch of 50.
92-
to_delete = a_ids[:batch_size]
93-
a_ids = a_ids[batch_size:]
94-
self._client.do_api_request(
95-
f'/v3/tags/{quote_plus(tag_id)}/{",".join([quote_plus(d) for d in to_delete])}', method='DELETE'
96-
)
100+
self.untag_entries(a_ids)
97101

98102

99103
class UserCategory(Streamable):

0 commit comments

Comments
 (0)