migrate project to uv
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import json
|
||||
@@ -12,8 +13,8 @@ from wallabag_api.wallabag import Wallabag
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
CONFIG_PATH = os.path.join(ROOT_DIR, "config.ini")
|
||||
ARTICLES_PATH = os.path.join(ROOT_DIR, "articles.json")
|
||||
DEFAULT_CONFIG_PATH = os.path.join(ROOT_DIR, "config.ini")
|
||||
DEFAULT_ARTICLES_PATH = os.path.join(ROOT_DIR, "articles.json")
|
||||
|
||||
|
||||
async def post_entry(
|
||||
@@ -25,7 +26,6 @@ async def post_entry(
|
||||
url=item["url"],
|
||||
archive=item["is_archived"],
|
||||
starred=item["is_starred"],
|
||||
# original_url=item["origin_url"],
|
||||
tags=",".join(item["tags"]),
|
||||
)
|
||||
logging.info(
|
||||
@@ -71,16 +71,56 @@ async def delete_all_entries(ids: List[int], w_api: Wallabag, max_requests=20):
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
|
||||
async def main():
|
||||
async with aiohttp.ClientSession(loop=asyncio.get_event_loop()) as session:
|
||||
configuration = dict(load_configuration(CONFIG_PATH))
|
||||
async def async_main(
|
||||
config_path: str = DEFAULT_CONFIG_PATH,
|
||||
articles_path: str = DEFAULT_ARTICLES_PATH,
|
||||
max_entries: int = 0,
|
||||
max_requests: int = 20,
|
||||
delete_after_import: bool = False,
|
||||
):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
configuration = dict(load_configuration(config_path))
|
||||
w_api = await connect_to_wallabag(configuration, session)
|
||||
|
||||
# entry = await w_api.get_entry(62)
|
||||
entries_id = await import_articles(
|
||||
w_api, articles_path, max_entries, max_requests
|
||||
)
|
||||
|
||||
entries_id = await import_articles(w_api, ARTICLES_PATH)
|
||||
await delete_all_entries(entries_id, w_api)
|
||||
if delete_after_import:
|
||||
await delete_all_entries(entries_id, w_api, max_requests)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Mass import articles to Wallabag")
|
||||
parser.add_argument(
|
||||
"--config", default=DEFAULT_CONFIG_PATH, help="Path to config file"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--articles", default=DEFAULT_ARTICLES_PATH, help="Path to articles JSON file"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max-entries",
|
||||
type=int,
|
||||
default=0,
|
||||
help="Maximum number of entries to import (0 = all)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max-requests", type=int, default=20, help="Maximum concurrent requests"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--delete-after-import", action="store_true", help="Delete entries after import"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
asyncio.run(
|
||||
async_main(
|
||||
args.config,
|
||||
args.articles,
|
||||
args.max_entries,
|
||||
args.max_requests,
|
||||
args.delete_after_import,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(), debug=True)
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user