mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 18:19:32 +00:00
refactor: rename folder -> category
This commit is contained in:
parent
2557db7502
commit
58e8a14b93
1 changed files with 26 additions and 27 deletions
53
feather.py
53
feather.py
|
|
@ -178,14 +178,14 @@ class ClientSession(ABC):
|
|||
pass
|
||||
|
||||
@abstractmethod
|
||||
def list_folders(self) -> list[Category]:
|
||||
def list_categories(self) -> list[Category]:
|
||||
"""
|
||||
Returns a list of all the categories on the server.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_unread_articles_in_folder(self, folder_id: Id, limit: int, continuation: int=0) -> list[Article]:
|
||||
def get_unread_articles_in_category(self, category_id: Id, limit: int, continuation: int=0) -> list[Article]:
|
||||
"""
|
||||
Returns a list of Articles in the given category. limit and continuation are required for pagination.
|
||||
"""
|
||||
|
|
@ -205,17 +205,17 @@ class GReaderSession(ClientSession):
|
|||
def mark_as_read(self, item_ids: list[Id]):
|
||||
self.greader.edit_tags(self.auth_token, self.csrf_token, item_ids=item_ids, add_tags=[google_reader.STREAM_READ])
|
||||
|
||||
def list_folders(self):
|
||||
folders = [tag for tag in self.greader.list_tags(self.auth_token) if tag.type == "folder"]
|
||||
def list_categories(self):
|
||||
categories = [tag for tag in self.greader.list_tags(self.auth_token) if tag.type == "folder"]
|
||||
l = []
|
||||
for folder in folders:
|
||||
folder_name = folder.label or label_name.search(folder.id).group(1)
|
||||
folder_id = folder.id
|
||||
l.append(Category(id=folder_id, title=folder_name))
|
||||
for category in categories:
|
||||
category_name = category.label or label_name.search(category.id).group(1)
|
||||
category_id = category.id
|
||||
l.append(Category(id=category_id, title=category_name))
|
||||
return l
|
||||
|
||||
def get_unread_articles_in_folder(self, folder_id, limit=500, continuation=0):
|
||||
items_ids = self.greader.get_stream_items_ids(self.auth_token, stream_id=folder_id, exclude_target="user/-/state/com.google/read", limit=limit, continuation=continuation)
|
||||
def get_unread_articles_in_category(self, category_id, limit=500, continuation=0):
|
||||
items_ids = self.greader.get_stream_items_ids(self.auth_token, stream_id=category_id, exclude_target="user/-/state/com.google/read", limit=limit, continuation=continuation)
|
||||
item_contents = self.greader.get_stream_items_contents(self.auth_token, self.csrf_token, item_ids=[item.id for item in items.item_refs])
|
||||
return [ GReaderArticle(self, item_content) for item_content in item_contents.items ]
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ class TRRSession(ClientSession):
|
|||
def mark_as_read(self, item_ids):
|
||||
self.ttrss.mark_read(item_ids)
|
||||
|
||||
def list_folders(self):
|
||||
def list_categories(self):
|
||||
self.feeds = {}
|
||||
def get_categories_recursive(parent_category, parent_categories=[]):
|
||||
categories = []
|
||||
|
|
@ -254,11 +254,11 @@ class TRRSession(ClientSession):
|
|||
tree = self.ttrss.get_feed_tree()
|
||||
return get_categories_recursive(tree["categories"])
|
||||
|
||||
def get_unread_articles_in_folder(self, folder_id, limit=100, continuation=0):
|
||||
headlines = self.ttrss.get_headlines(feed_id=folder_id, limit=limit, skip=continuation, is_cat=True, show_excerpt=True, show_content=True, view_mode="unread", include_attachments=True, include_nested=False)
|
||||
def get_unread_articles_in_category(self, category_id, limit=100, continuation=0):
|
||||
headlines = self.ttrss.get_headlines(feed_id=category_id, limit=limit, skip=continuation, is_cat=True, show_excerpt=True, show_content=True, view_mode="unread", include_attachments=True, include_nested=False)
|
||||
return [ TTRArticle(self, headline) for headline in headlines ]
|
||||
|
||||
def make_client_session(config: Config):
|
||||
def make_client_session(config: Config) -> ClientSession:
|
||||
api = config.server_api
|
||||
if api == "googlereader":
|
||||
return GReaderSession(config)
|
||||
|
|
@ -307,20 +307,20 @@ def truncate_filename(config, filename):
|
|||
return filename[:cutoff] + '…' + suffix
|
||||
|
||||
def get_html_path(config, item_json):
|
||||
folder_directory = config.html_root
|
||||
for folder in item_json["folder"]["parents"]:
|
||||
folder_directory /= escape_filename(config, config.item_category_template.render(folder))
|
||||
folder_directory /= escape_filename(config, config.item_category_template.render(item_json["folder"]))
|
||||
folder_directory.mkdir(parents=True, exist_ok=True) # TODO move
|
||||
category_directory = config.html_root
|
||||
for category in item_json["category"]["parents"]:
|
||||
category_directory /= escape_filename(config, config.item_category_template.render(category))
|
||||
category_directory /= escape_filename(config, config.item_category_template.render(item_json["category"]))
|
||||
category_directory.mkdir(parents=True, exist_ok=True) # TODO move
|
||||
|
||||
html_name = truncate_filename(config, escape_filename(config, config.item_filename_template.render(item_json)))
|
||||
|
||||
return folder_directory / html_name
|
||||
return category_directory / html_name
|
||||
|
||||
def format_datetime(config, timestamp):
|
||||
return datetime.fromtimestamp(timestamp, config.timezone).strftime(config.time_format)
|
||||
|
||||
def set_computed_fields_json(config, item_json):
|
||||
def set_computed_fields_json(config, item_json): # TODO: clean
|
||||
item_json["published_formatted"] = format_datetime(config, item_json["published"])
|
||||
item_json["updated_formatted"] = format_datetime(config, item_json["updated"])
|
||||
item_json["html_path"] = str(get_html_path(config, item_json).relative_to(config.html_root))
|
||||
|
|
@ -333,14 +333,13 @@ def synchronize_with_server(config, client_session):
|
|||
new_items, updated_items = 0, 0
|
||||
grabbed_item_paths = []
|
||||
|
||||
folders = client_session.list_folders()
|
||||
for category in folders:
|
||||
folder_path, folder_id = category.title, category.id
|
||||
print(f" Updating folder {folder_path}") # TODO fixme
|
||||
categories = client_session.list_categories()
|
||||
for category in categories:
|
||||
print(f" Updating category {category.title}")
|
||||
|
||||
remaining, continuation = True, 0
|
||||
while remaining:
|
||||
articles = client_session.get_unread_articles_in_folder(folder_id, limit=config.items_per_query, continuation=continuation)
|
||||
articles = client_session.get_unread_articles_in_category(category.id, limit=config.items_per_query, continuation=continuation)
|
||||
if len(articles) >= config.items_per_query:
|
||||
continuation += len(articles)
|
||||
else:
|
||||
|
|
@ -348,7 +347,7 @@ def synchronize_with_server(config, client_session):
|
|||
|
||||
for item in articles:
|
||||
item_json = item.asdict()
|
||||
item_json["folder"] = category.asdict()
|
||||
item_json["category"] = category.asdict()
|
||||
set_computed_fields_json(config, item_json)
|
||||
|
||||
json_path = config.json_root / f"{ sha256(str(item_json["id"]).encode("utf-8")).hexdigest() }.json"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue