65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
"""Example usage of the Wallabag API."""
|
|
|
|
import asyncio
|
|
|
|
import aiohttp
|
|
|
|
from wallabag_api.wallabag import Wallabag
|
|
|
|
|
|
async def main():
|
|
my_host = "http://localhost:8080"
|
|
|
|
params = {
|
|
"username": "foxmask",
|
|
"password": "mypass",
|
|
"client_id": "myid",
|
|
"client_secret": "mysecret",
|
|
}
|
|
|
|
# get a new token
|
|
token = await Wallabag.get_token(host=my_host, **params)
|
|
|
|
# initializing
|
|
async with aiohttp.ClientSession() as session:
|
|
wall = Wallabag(
|
|
host=my_host,
|
|
client_secret=params.get("client_secret"),
|
|
client_id=params.get("client_id"),
|
|
token=token,
|
|
extension="json",
|
|
aio_sess=session,
|
|
)
|
|
|
|
url = "https://foxmask.trigger-happy.eu"
|
|
title = "foxmask's blog"
|
|
|
|
await wall.post_entries(url, title, "", 0, 0)
|
|
|
|
url = "https://trigger-happy.eu"
|
|
title = "Project TriggerHappy"
|
|
|
|
await wall.post_entries(url, title, "", 0, 0)
|
|
|
|
# get all the articles
|
|
my_wallabag = await wall.get_entries()
|
|
|
|
all_article = my_wallabag["_embedded"]["items"]
|
|
|
|
for article in all_article:
|
|
print(article["id"], article["title"])
|
|
|
|
# get the version of wallabag
|
|
version = await wall.version
|
|
print(f"version {version}")
|
|
|
|
# export one article into PDF
|
|
my_wallabag = await wall.get_entry_export(entry=1)
|
|
with open("foobar.pdf", "wb") as f:
|
|
f.write(my_wallabag)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|