stuff
This commit is contained in:
parent
3f1ed1403e
commit
a3dcfab1ce
24
helpers.py
Normal file
24
helpers.py
Normal file
@ -0,0 +1,24 @@
|
||||
import configparser
|
||||
from wallabag_api.wallabag import Wallabag
|
||||
import aiohttp
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def load_configuration(path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path)
|
||||
return config["Wallabag Configuration"]
|
||||
|
||||
|
||||
async def connect_to_wallabag(
|
||||
configuration: Dict[str, str], session: aiohttp.ClientSession
|
||||
) -> Wallabag:
|
||||
configuration["access_token"] = await Wallabag.get_token(**configuration)
|
||||
|
||||
return Wallabag(
|
||||
host=configuration["host"],
|
||||
token=configuration["access_token"],
|
||||
client_id=configuration["client_id"],
|
||||
client_secret=configuration["client_secret"],
|
||||
aio_sess=session,
|
||||
)
|
20
wallabag_explorer.py
Normal file
20
wallabag_explorer.py
Normal file
@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import aiohttp
|
||||
from wallabag_api.wallabag import Wallabag
|
||||
from helpers import load_configuration, connect_to_wallabag
|
||||
|
||||
async def get_paginated_entries(w_api: Wallabag, per_page: int, page: int):
|
||||
return await w_api.get_entries(perPage=per_page, page=page)
|
||||
|
||||
|
||||
async def main(path: str, per_page=10):
|
||||
async with aiohttp.ClientSession(loop=asyncio.get_event_loop()) as session:
|
||||
configuration = dict(load_configuration(path))
|
||||
w_api = await connect_to_wallabag(configuration, session)
|
||||
|
||||
for page in range(1, 10):
|
||||
entries = await get_paginated_entries(w_api, per_page, page)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main("config.ini"), debug=True)
|
@ -4,6 +4,7 @@ import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Any, Dict, List
|
||||
from helpers import load_configuration, connect_to_wallabag
|
||||
|
||||
import aiohttp
|
||||
from wallabag_api.wallabag import Wallabag
|
||||
@ -15,26 +16,6 @@ CONFIG_PATH = os.path.join(ROOT_DIR, "config.ini")
|
||||
ARTICLES_PATH = os.path.join(ROOT_DIR, "articles.json")
|
||||
|
||||
|
||||
def load_configuration(path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path)
|
||||
return config["Wallabag Configuration"]
|
||||
|
||||
|
||||
async def connect_to_wallabag(
|
||||
configuration: Dict[str, str], session: aiohttp.ClientSession
|
||||
) -> Wallabag:
|
||||
configuration["access_token"] = await Wallabag.get_token(**configuration)
|
||||
|
||||
return Wallabag(
|
||||
host=configuration["host"],
|
||||
token=configuration["access_token"],
|
||||
client_id=configuration["client_id"],
|
||||
client_secret=configuration["client_secret"],
|
||||
aio_sess=session,
|
||||
)
|
||||
|
||||
|
||||
async def post_entry(
|
||||
w_api: Wallabag, item: Dict[str, str], semaphore: asyncio.Semaphore
|
||||
):
|
||||
@ -44,7 +25,7 @@ async def post_entry(
|
||||
url=item["url"],
|
||||
archive=item["is_archived"],
|
||||
starred=item["is_starred"],
|
||||
original_url=item["origin_url"],
|
||||
# original_url=item["origin_url"],
|
||||
tags=",".join(item["tags"]),
|
||||
)
|
||||
logging.info(
|
||||
@ -95,7 +76,9 @@ async def main():
|
||||
configuration = dict(load_configuration(CONFIG_PATH))
|
||||
w_api = await connect_to_wallabag(configuration, session)
|
||||
|
||||
entries_id = await import_articles(w_api, ARTICLES_PATH, max_entries=20, max_requests=20)
|
||||
# entry = await w_api.get_entry(62)
|
||||
|
||||
entries_id = await import_articles(w_api, ARTICLES_PATH)
|
||||
await delete_all_entries(entries_id, w_api)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user