|
3 | 3 | handy getter methods, but otherwise you can just use a .json property to access the
|
4 | 4 | raw json passed back by the client.
|
5 | 5 | """
|
6 |
| -from typing import Any, Callable, Dict, List, Optional, Union |
| 6 | +import logging |
| 7 | +from typing import Any, Callable, Dict, List, Optional, Union, Set |
7 | 8 | from urllib.parse import quote_plus
|
8 | 9 |
|
| 10 | +from requests import HTTPError, Response |
| 11 | + |
9 | 12 | from feedly.api_client.protocol import APIClient
|
10 |
| -from feedly.api_client.stream import EnterpriseStreamId, STREAM_SOURCE_ENTERPRISE, STREAM_SOURCE_USER, StreamBase, StreamIdBase, StreamOptions, UserStreamId |
| 13 | +from feedly.api_client.stream import EnterpriseStreamId, STREAM_SOURCE_ENTERPRISE, STREAM_SOURCE_USER, StreamBase, \ |
| 14 | + StreamIdBase, StreamOptions, UserStreamId |
| 15 | + |
| 16 | +logger = logging.getLogger(__name__) |
11 | 17 |
|
12 | 18 |
|
13 | 19 | class FeedlyData:
|
@@ -72,9 +78,25 @@ class TagBase(Streamable):
|
72 | 78 | def tag_entry(self, entry_id:str):
|
73 | 79 | self._client.do_api_request(f'/v3/tags/{quote_plus(self["id"])}', method='put', data={'entryId': entry_id})
|
74 | 80 |
|
75 |
| - def tag_entries(self, entry_ids: List[str]): |
76 |
| - self._client.do_api_request(f'/v3/tags/{quote_plus(self["id"])}', method='put', |
77 |
| - data={'entryIds': [entry_id for entry_id in entry_ids]}) |
| 81 | + def tag_entries(self, entry_ids: List[str], errors_to_ignore: Set[int] = None): |
| 82 | + """ |
| 83 | + Tag the given entries. |
| 84 | + Will ignore given error_codes (default is only ignore 409, that happens when a duplicate is already tagged) |
| 85 | + """ |
| 86 | + if errors_to_ignore is None: |
| 87 | + errors_to_ignore = {409} |
| 88 | + for i in range(0, len(entry_ids), 50): |
| 89 | + self._tag_entries_batch(entry_ids[i: i + 50], errors_to_ignore) |
| 90 | + |
| 91 | + def _tag_entries_batch(self, entry_ids: List[str], errors_to_ignore: Set[int]): |
| 92 | + try: |
| 93 | + self._client.do_api_request(f'/v3/tags/{quote_plus(self["id"])}', method='put', data={'entryIds': entry_ids}) |
| 94 | + except HTTPError as e: |
| 95 | + resp: Response = e.response |
| 96 | + if resp.status_code in errors_to_ignore: |
| 97 | + logger.warning(f"Got 409 Client Error while tagging batch of entries: {resp.text}") |
| 98 | + else: |
| 99 | + raise e |
78 | 100 |
|
79 | 101 | def untag_entry(self, entry_id: str):
|
80 | 102 | self.untag_entries([entry_id])
|
|
0 commit comments