mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 10:09: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
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def list_folders(self) -> list[Category]:
|
def list_categories(self) -> list[Category]:
|
||||||
"""
|
"""
|
||||||
Returns a list of all the categories on the server.
|
Returns a list of all the categories on the server.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@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.
|
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]):
|
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])
|
self.greader.edit_tags(self.auth_token, self.csrf_token, item_ids=item_ids, add_tags=[google_reader.STREAM_READ])
|
||||||
|
|
||||||
def list_folders(self):
|
def list_categories(self):
|
||||||
folders = [tag for tag in self.greader.list_tags(self.auth_token) if tag.type == "folder"]
|
categories = [tag for tag in self.greader.list_tags(self.auth_token) if tag.type == "folder"]
|
||||||
l = []
|
l = []
|
||||||
for folder in folders:
|
for category in categories:
|
||||||
folder_name = folder.label or label_name.search(folder.id).group(1)
|
category_name = category.label or label_name.search(category.id).group(1)
|
||||||
folder_id = folder.id
|
category_id = category.id
|
||||||
l.append(Category(id=folder_id, title=folder_name))
|
l.append(Category(id=category_id, title=category_name))
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def get_unread_articles_in_folder(self, folder_id, limit=500, continuation=0):
|
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=folder_id, exclude_target="user/-/state/com.google/read", limit=limit, continuation=continuation)
|
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])
|
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 ]
|
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):
|
def mark_as_read(self, item_ids):
|
||||||
self.ttrss.mark_read(item_ids)
|
self.ttrss.mark_read(item_ids)
|
||||||
|
|
||||||
def list_folders(self):
|
def list_categories(self):
|
||||||
self.feeds = {}
|
self.feeds = {}
|
||||||
def get_categories_recursive(parent_category, parent_categories=[]):
|
def get_categories_recursive(parent_category, parent_categories=[]):
|
||||||
categories = []
|
categories = []
|
||||||
|
|
@ -254,11 +254,11 @@ class TRRSession(ClientSession):
|
||||||
tree = self.ttrss.get_feed_tree()
|
tree = self.ttrss.get_feed_tree()
|
||||||
return get_categories_recursive(tree["categories"])
|
return get_categories_recursive(tree["categories"])
|
||||||
|
|
||||||
def get_unread_articles_in_folder(self, folder_id, limit=100, continuation=0):
|
def get_unread_articles_in_category(self, category_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)
|
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 ]
|
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
|
api = config.server_api
|
||||||
if api == "googlereader":
|
if api == "googlereader":
|
||||||
return GReaderSession(config)
|
return GReaderSession(config)
|
||||||
|
|
@ -307,20 +307,20 @@ def truncate_filename(config, filename):
|
||||||
return filename[:cutoff] + '…' + suffix
|
return filename[:cutoff] + '…' + suffix
|
||||||
|
|
||||||
def get_html_path(config, item_json):
|
def get_html_path(config, item_json):
|
||||||
folder_directory = config.html_root
|
category_directory = config.html_root
|
||||||
for folder in item_json["folder"]["parents"]:
|
for category in item_json["category"]["parents"]:
|
||||||
folder_directory /= escape_filename(config, config.item_category_template.render(folder))
|
category_directory /= escape_filename(config, config.item_category_template.render(category))
|
||||||
folder_directory /= escape_filename(config, config.item_category_template.render(item_json["folder"]))
|
category_directory /= escape_filename(config, config.item_category_template.render(item_json["category"]))
|
||||||
folder_directory.mkdir(parents=True, exist_ok=True) # TODO move
|
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)))
|
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):
|
def format_datetime(config, timestamp):
|
||||||
return datetime.fromtimestamp(timestamp, config.timezone).strftime(config.time_format)
|
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["published_formatted"] = format_datetime(config, item_json["published"])
|
||||||
item_json["updated_formatted"] = format_datetime(config, item_json["updated"])
|
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))
|
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
|
new_items, updated_items = 0, 0
|
||||||
grabbed_item_paths = []
|
grabbed_item_paths = []
|
||||||
|
|
||||||
folders = client_session.list_folders()
|
categories = client_session.list_categories()
|
||||||
for category in folders:
|
for category in categories:
|
||||||
folder_path, folder_id = category.title, category.id
|
print(f" Updating category {category.title}")
|
||||||
print(f" Updating folder {folder_path}") # TODO fixme
|
|
||||||
|
|
||||||
remaining, continuation = True, 0
|
remaining, continuation = True, 0
|
||||||
while remaining:
|
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:
|
if len(articles) >= config.items_per_query:
|
||||||
continuation += len(articles)
|
continuation += len(articles)
|
||||||
else:
|
else:
|
||||||
|
|
@ -348,7 +347,7 @@ def synchronize_with_server(config, client_session):
|
||||||
|
|
||||||
for item in articles:
|
for item in articles:
|
||||||
item_json = item.asdict()
|
item_json = item.asdict()
|
||||||
item_json["folder"] = category.asdict()
|
item_json["category"] = category.asdict()
|
||||||
set_computed_fields_json(config, item_json)
|
set_computed_fields_json(config, item_json)
|
||||||
|
|
||||||
json_path = config.json_root / f"{ sha256(str(item_json["id"]).encode("utf-8")).hexdigest() }.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