Compare commits
25 Commits
wallabag_a
...
1.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c269fba43 | ||
|
|
07d3840ca6 | ||
|
|
43b1602cbb | ||
|
|
c6f62a4697 | ||
|
|
63cd4e80cb | ||
|
|
b7d4abb0d1 | ||
|
|
5b3cd028a7 | ||
|
|
0c40a35559 | ||
|
|
a9e0335054 | ||
|
|
6a7573069b | ||
|
|
c92e55208a | ||
|
|
aea9df0978 | ||
|
|
9fbd7cc28d | ||
|
|
3264fda186 | ||
|
|
922c47f1cf | ||
|
|
fa9c6360a5 | ||
|
|
12c30c6af3 | ||
|
|
546d744722 | ||
|
|
fbf71efa71 | ||
|
|
c5c7fa06b1 | ||
|
|
86e5c02b0f | ||
|
|
99bfd7c08b | ||
|
|
8ce21dcdd3 | ||
|
|
b11f648ec9 | ||
|
|
4ad230a83e |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1 +1,8 @@
|
||||
.idea
|
||||
*.log
|
||||
*.pot
|
||||
*.pyc
|
||||
.coverage
|
||||
*.json
|
||||
.tox
|
||||
build
|
||||
|
||||
91
README.rst
91
README.rst
@@ -1,13 +1,24 @@
|
||||
.. image:: http://img.shields.io/badge/python-3.6-orange.svg
|
||||
:target: https://pypi.python.org/pypi/django-th/
|
||||
:alt: Python version supported
|
||||
|
||||
|
||||
.. image:: http://img.shields.io/badge/license-BSD-blue.svg
|
||||
:target: https://pypi.python.org/pypi/django-th/
|
||||
:alt: License
|
||||
|
||||
|
||||
============
|
||||
Wallabag API
|
||||
============
|
||||
|
||||
Python API for Wallabag v2
|
||||
Python API for Wallabag v2.2.3
|
||||
|
||||
Requirements :
|
||||
==============
|
||||
|
||||
* requests
|
||||
* aiohttp
|
||||
|
||||
|
||||
Installation:
|
||||
=============
|
||||
@@ -16,7 +27,7 @@ to get the project, from your virtualenv, do :
|
||||
|
||||
.. code:: python
|
||||
|
||||
git clone https://github.com/foxmask/wallabag-api/
|
||||
git clone https://github.com/push-things/wallabag_api/
|
||||
|
||||
|
||||
or
|
||||
@@ -35,30 +46,71 @@ Creating a post :
|
||||
|
||||
.. code:: python
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
import aiohttp
|
||||
import asyncio
|
||||
|
||||
from wallabag_api.wallabag import Wallabag
|
||||
# settings
|
||||
# settings
|
||||
my_host = 'http://localhost:8080'
|
||||
|
||||
|
||||
async def main(loop):
|
||||
|
||||
params = {'username': 'foxmask',
|
||||
'password': 'mypass',
|
||||
'client_id': 'myid',
|
||||
'client_secret': 'mysecret'}
|
||||
my_host = 'http://localhost:8080'
|
||||
# get token
|
||||
token = Wallabag.get_token(host=my_host, **params)
|
||||
'client_secret': 'mysecret',
|
||||
'extension': 'pdf'}
|
||||
|
||||
# create a post
|
||||
wall = Wallabag(host=my_host, client_secret='mysecret', client_id='myid', token=token)
|
||||
# get a new token
|
||||
token = await Wallabag.get_token(host=my_host, **params)
|
||||
|
||||
my_url = 'https://blog.trigger-happy.eu'
|
||||
my_title = 'Trigger Happy blog'
|
||||
my_tags = ['python', 'wallabag']
|
||||
# initializing
|
||||
async with aiohttp.ClientSession(loop=loop) as session:
|
||||
wall = Wallabag(host=my_host,
|
||||
client_secret=params.get('client_secret'),
|
||||
client_id=params.get('client_id'),
|
||||
token=token,
|
||||
extension=params['extension'],
|
||||
aio_sess=session)
|
||||
|
||||
wall.post_entries(url=my_url, title=my_title, tags=my_tags)
|
||||
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 TrigerHappy'
|
||||
|
||||
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__':
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main(loop))
|
||||
|
||||
|
||||
this will give you something like this :
|
||||
|
||||
.. image:: https://github.com/foxmask/wallabag_api/blob/master/wallabag.png
|
||||
|
||||
.. image:: https://github.com/push-things/wallabag_api/blob/master/wallabag.png
|
||||
|
||||
|
||||
Testing :
|
||||
@@ -66,11 +118,13 @@ Testing :
|
||||
|
||||
Install Wallabag V2 on your own host like explain here http://doc.wallabag.org/en/v2/user/installation.html
|
||||
|
||||
Then run the development version (with make run)
|
||||
|
||||
Then create a client API like explain here http://doc.wallabag.org/en/v2/developer/api.html
|
||||
|
||||
this will give you somthing like this
|
||||
this will give you something like this
|
||||
|
||||
.. image:: https://github.com/foxmask/wallabag_api/blob/master/wallabag_api_key.png
|
||||
.. image:: https://github.com/push-things/wallabag_api/blob/master/wallabag_api_key.png
|
||||
|
||||
Then replace the client_id / client_secret / login / pass to wallabag_test.py and run
|
||||
|
||||
@@ -78,4 +132,3 @@ Then replace the client_id / client_secret / login / pass to wallabag_test.py an
|
||||
|
||||
python wallabag_test.py
|
||||
|
||||
|
||||
|
||||
18
setup.py
18
setup.py
@@ -1,28 +1,30 @@
|
||||
from setuptools import setup, find_packages
|
||||
from wallabag_api import __version__ as version
|
||||
|
||||
desc = 'Wallabag API to add every pages you want to your Wallabag account'
|
||||
long_desc = 'Wallabag is a "read it later" service, and that Wallabag API allow you to save web pages ' \
|
||||
'to your own account'
|
||||
install_requires = [
|
||||
'requests==2.18.4',
|
||||
'aiohttp',
|
||||
]
|
||||
|
||||
setup(
|
||||
name='wallabag_api',
|
||||
version=version,
|
||||
description='Wallabag API to add every pages you want to your Wallabag account',
|
||||
description=desc,
|
||||
long_description=long_desc,
|
||||
author='FoxMaSk',
|
||||
author_email='foxmask@trigger-happy.eu',
|
||||
url='https://github.com/foxmask/wallabag_api',
|
||||
download_url="https://github.com/foxmask/wallabag_api/archive/"
|
||||
"wallabag_api-" + version + ".zip",
|
||||
url='https://github.com/push-things/wallabag_api',
|
||||
download_url="https://github.com/push-things/wallabag_api/archive/wallabag_api-" + version + ".zip",
|
||||
packages=find_packages(),
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: BSD License',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Topic :: Internet',
|
||||
'Topic :: Communications',
|
||||
],
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
VERSION = (1, 1, 2) # PEP 386
|
||||
VERSION = (1, 2, 1) # PEP 386
|
||||
__version__ = ".".join([str(x) for x in VERSION])
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# coding: utf-8
|
||||
import requests
|
||||
from requests import HTTPError
|
||||
import logging
|
||||
import aiohttp
|
||||
from aiohttp.http_exceptions import HttpProcessingError
|
||||
from aiohttp.client_exceptions import ClientResponseError
|
||||
|
||||
__author__ = 'foxmask'
|
||||
|
||||
|
||||
logging.basicConfig(format='%(message)s', level=logging.INFO)
|
||||
|
||||
__all__ = ['Wallabag']
|
||||
@@ -25,6 +25,7 @@ class Wallabag(object):
|
||||
format = ''
|
||||
username = ''
|
||||
password = ''
|
||||
aio_sess = None
|
||||
|
||||
def __init__(self,
|
||||
host='',
|
||||
@@ -32,8 +33,9 @@ class Wallabag(object):
|
||||
client_id='',
|
||||
client_secret='',
|
||||
extension='json',
|
||||
user_agent="WallabagPython/1.0 "
|
||||
"+https://github.com/foxmask/wallabag-api"):
|
||||
user_agent="WallabagPython/1.2.2 "
|
||||
" +https://github.com/push-things/wallabag-api",
|
||||
aio_sess=None):
|
||||
"""
|
||||
init variable
|
||||
:param host: string url to the official API Wallabag
|
||||
@@ -42,6 +44,7 @@ class Wallabag(object):
|
||||
:param client_secret client secret
|
||||
:param extension: xml|json|txt|csv|pdf|epub|mobi|html
|
||||
:param user_agent
|
||||
:param aio_sess aiohttp session
|
||||
"""
|
||||
self.host = host
|
||||
self.client_id = client_id
|
||||
@@ -49,68 +52,85 @@ class Wallabag(object):
|
||||
self.token = token
|
||||
self.format = extension
|
||||
self.user_agent = user_agent
|
||||
|
||||
self.aio_sess = aio_sess
|
||||
if self.format not in self.EXTENTIONS:
|
||||
raise ValueError("format invalid {0} should be one of {1}".format(
|
||||
self.format, self.EXTENTIONS))
|
||||
|
||||
def get_host(self):
|
||||
"""
|
||||
get the host from which to get API
|
||||
:return host
|
||||
"""
|
||||
return self.host
|
||||
|
||||
def query(self, path, method='get', **params):
|
||||
async def query(self, path, method='get', **params):
|
||||
"""
|
||||
Do a query to the System API
|
||||
|
||||
:param path: url to the API
|
||||
:param method: the kind of query to do
|
||||
:param params: a dict with all the
|
||||
necessary things to query the API
|
||||
:return json data
|
||||
"""
|
||||
if method in ('get', 'post', 'patch', 'delete', 'put', 'get_token'):
|
||||
if method in ('get', 'post', 'patch', 'delete', 'put'):
|
||||
full_path = self.host + path
|
||||
if method == 'get':
|
||||
r = requests.get(self.get_host() + path, params=params)
|
||||
resp = await self.aio_sess.get(full_path, params=params)
|
||||
elif method == 'post':
|
||||
r = requests.post(self.get_host() + path, data=params)
|
||||
resp = await self.aio_sess.post(full_path, data=params)
|
||||
elif method == 'patch':
|
||||
r = requests.patch(self.get_host() + path, data=params)
|
||||
resp = await self.aio_sess.patch(full_path, data=params)
|
||||
elif method == 'delete':
|
||||
r = requests.delete(self.get_host() + path, headers=params)
|
||||
resp = await self.aio_sess.delete(full_path, headers=params)
|
||||
elif method == 'put':
|
||||
r = requests.put(self.get_host() + path, params=params)
|
||||
return self.handle_json_response(r)
|
||||
resp = await self.aio_sess.put(full_path, data=params)
|
||||
|
||||
async with resp:
|
||||
# return the content if its a binary one
|
||||
if resp.content_type.startswith('application/pdf') or \
|
||||
resp.content_type.startswith('application/epub'):
|
||||
return await resp.read()
|
||||
|
||||
return await self.handle_json_response(resp)
|
||||
else:
|
||||
raise ValueError('method expected : get, post, patch, delete or put')
|
||||
raise ValueError('method expected: get, post, patch, delete, put')
|
||||
|
||||
@staticmethod
|
||||
def handle_json_response(responses):
|
||||
async def handle_json_response(responses):
|
||||
"""
|
||||
get the json data response
|
||||
:param responses: the json response
|
||||
:return the json data without 'root' node
|
||||
"""
|
||||
json_data = {}
|
||||
if responses.status_code != 200:
|
||||
err_msg = HTTPError(responses.status_code, responses.reason)
|
||||
msg = "Wallabag: error {err_msg}".format(err_msg=err_msg)
|
||||
logging.error(msg)
|
||||
raise HTTPError(msg)
|
||||
if responses.status != 200:
|
||||
err_msg = HttpProcessingError(code=responses.status,
|
||||
message=await responses.json())
|
||||
logging.error("Wallabag: aiohttp error {err_msg}".format(
|
||||
err_msg=err_msg))
|
||||
else:
|
||||
try:
|
||||
json_data = responses.json()
|
||||
except:
|
||||
for error in json_data['errors']:
|
||||
error_json = json_data['errors'][error]['content']
|
||||
logging.error("Wallabag: {error}".format(error=error_json))
|
||||
return json_data
|
||||
except ClientResponseError as e:
|
||||
# sometimes json_data does not return any json() without
|
||||
# any error. This is due to the grabbing URL which "rejects"
|
||||
# the URL
|
||||
logging.error("Wallabag: aiohttp error {code} {message}"
|
||||
.format(code=e.code, message=e.message))
|
||||
return await json_data
|
||||
|
||||
@staticmethod
|
||||
def __get_attr(what, type_attr, value_attr, **kwargs):
|
||||
"""
|
||||
get the value of a parm
|
||||
:param what: string parm
|
||||
:param type_attr: type of parm
|
||||
:param value_attr:
|
||||
:param kwargs:
|
||||
:return: value of the parm
|
||||
"""
|
||||
value = int(kwargs[what]) if type_attr == 'int' else kwargs[what]
|
||||
if what in kwargs and value in value_attr:
|
||||
return value
|
||||
|
||||
# ENTRIES
|
||||
def get_entries(self, **kwargs):
|
||||
async def get_entries(self, **kwargs):
|
||||
"""
|
||||
|
||||
GET /api/entries.{_format}
|
||||
|
||||
Retrieve all entries. It could be filtered by many options.
|
||||
@@ -124,11 +144,12 @@ class Wallabag(object):
|
||||
page: int default 1 what page you want
|
||||
perPage: int default 30 result per page
|
||||
tags: list of tags url encoded.
|
||||
since: int default 0 from what timestamp you want
|
||||
Will returns entries that matches ALL tags
|
||||
:return data related to the ext
|
||||
"""
|
||||
# default values
|
||||
params = {'access_token': self.token,
|
||||
params = dict({'access_token': self.token,
|
||||
'archive': 0,
|
||||
'star': 0,
|
||||
'delete': 0,
|
||||
@@ -136,28 +157,40 @@ class Wallabag(object):
|
||||
'order': 'desc',
|
||||
'page': 1,
|
||||
'perPage': 30,
|
||||
'tags': []}
|
||||
'tags': '',
|
||||
'since': 0})
|
||||
|
||||
params['archive'] = self.__get_attr(what='archive',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**params)
|
||||
params['star'] = self.__get_attr(what='star',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**params)
|
||||
params['delete'] = self.__get_attr(what='delete',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**params)
|
||||
params['order'] = self.__get_attr(what='order',
|
||||
type_attr=str,
|
||||
value_attr=('asc', 'desc'),
|
||||
**params)
|
||||
|
||||
if 'archive' in kwargs and int(kwargs['archive']) in (0, 1):
|
||||
params['archive'] = int(kwargs['archive'])
|
||||
if 'star' in kwargs and int(kwargs['star']) in (0, 1):
|
||||
params['star'] = int(kwargs['star'])
|
||||
if 'delete' in kwargs and int(kwargs['delete']) in (0, 1):
|
||||
params['delete'] = int(kwargs['delete'])
|
||||
if 'order' in kwargs and kwargs['order'] in ('asc', 'desc'):
|
||||
params['order'] = kwargs['order']
|
||||
if 'page' in kwargs and isinstance(kwargs['page'], int):
|
||||
params['page'] = kwargs['page']
|
||||
if 'perPage' in kwargs and isinstance(kwargs['perPage'], int):
|
||||
params['perPage'] = kwargs['perPage']
|
||||
if 'tags' in kwargs and isinstance(kwargs['tags'], list):
|
||||
params['tags'] = kwargs['tags']
|
||||
params['tags'] = ', '.join(kwargs['tags'])
|
||||
if 'since' in kwargs and isinstance(kwargs['since'], int):
|
||||
params['since'] = kwargs['since']
|
||||
|
||||
path = '/api/entries.{ext}'.format(ext=self.format)
|
||||
|
||||
return self.query(path, "get", **params)
|
||||
return await self.query(path, "get", **params)
|
||||
|
||||
def post_entries(self, url, title='', tags='', starred=0, archive=0):
|
||||
async def post_entries(self, url, title='', tags='', starred=0, archive=0):
|
||||
"""
|
||||
POST /api/entries.{_format}
|
||||
|
||||
@@ -172,12 +205,12 @@ class Wallabag(object):
|
||||
"""
|
||||
params = {'access_token': self.token, 'url': url, 'title': title,
|
||||
'tags': tags, 'starred': starred, 'archive': archive}
|
||||
if len(tags) > 0 and isinstance(tags, list):
|
||||
params['tags'] = ', '.join(tags)
|
||||
if len(tags) > 0 and ',' in tags:
|
||||
params['tags'] = tags.split(',')
|
||||
path = '/api/entries.{ext}'.format(ext=self.format)
|
||||
return self.query(path, "post", **params)
|
||||
return await self.query(path, "post", **params)
|
||||
|
||||
def get_entry(self, entry):
|
||||
async def get_entry(self, entry):
|
||||
"""
|
||||
GET /api/entries/{entry}.{_format}
|
||||
|
||||
@@ -187,10 +220,11 @@ class Wallabag(object):
|
||||
:return data related to the ext
|
||||
"""
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/entries/{entry}.{ext}'.format(entry=entry, ext=self.format)
|
||||
return self.query(url, "get", **params)
|
||||
url = '/api/entries/{entry}.{ext}'.format(entry=entry,
|
||||
ext=self.format)
|
||||
return await self.query(url, "get", **params)
|
||||
|
||||
def patch_entries(self, entry, **kwargs):
|
||||
async def patch_entries(self, entry, **kwargs):
|
||||
"""
|
||||
PATCH /api/entries/{entry}.{_format}
|
||||
|
||||
@@ -218,17 +252,29 @@ class Wallabag(object):
|
||||
params['title'] = kwargs['title']
|
||||
if 'tags' in kwargs and isinstance(kwargs['tags'], list):
|
||||
params['tags'] = ', '.join(kwargs['tags'])
|
||||
if 'archive' in kwargs and int(kwargs['archive']) in (0, 1):
|
||||
params['archive'] = int(kwargs['archive'])
|
||||
if 'star' in kwargs and int(kwargs['star']) in (0, 1):
|
||||
params['star'] = int(kwargs['star'])
|
||||
if 'delete' in kwargs and int(kwargs['delete']) in (0, 1):
|
||||
params['delete'] = int(kwargs['delete'])
|
||||
|
||||
params['archive'] = self.__get_attr(what='archive',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**kwargs)
|
||||
params['star'] = self.__get_attr(what='star',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**kwargs)
|
||||
params['delete'] = self.__get_attr(what='delete',
|
||||
type_attr=int,
|
||||
value_attr=(0, 1),
|
||||
**kwargs)
|
||||
params['order'] = self.__get_attr(what='order',
|
||||
type_attr=str,
|
||||
value_attr=('asc', 'desc'),
|
||||
**kwargs)
|
||||
|
||||
path = '/api/entries/{entry}.{ext}'.format(
|
||||
entry=entry, ext=self.format)
|
||||
return self.query(path, "patch", **params)
|
||||
return await self.query(path, "patch", **params)
|
||||
|
||||
def get_entry_export(self, entry):
|
||||
async def get_entry_export(self, entry):
|
||||
"""
|
||||
GET /api/entries/{entry}/export.{_format}
|
||||
|
||||
@@ -240,9 +286,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/entries/{entry}/export.{ext}'.format(entry=entry,
|
||||
ext=self.format)
|
||||
return self.query(url, "get", **params)
|
||||
return await self.query(url, "get", **params)
|
||||
|
||||
def patch_entry_reload(self, entry):
|
||||
async def patch_entry_reload(self, entry):
|
||||
"""
|
||||
PATCH /api/entries/{entry}/reload.{_format}
|
||||
|
||||
@@ -256,9 +302,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/entries/{entry}/reload.{ext}'.format(entry=entry,
|
||||
ext=self.format)
|
||||
return self.query(url, "patch", **params)
|
||||
return await self.query(url, "patch", **params)
|
||||
|
||||
def delete_entries(self, entry):
|
||||
async def delete_entries(self, entry):
|
||||
"""
|
||||
DELETE /api/entries/{entry}.{_format}
|
||||
|
||||
@@ -271,9 +317,9 @@ class Wallabag(object):
|
||||
params = {'Authorization': 'Bearer {}'.format(self.token)}
|
||||
path = '/api/entries/{entry}.{ext}'.format(
|
||||
entry=entry, ext=self.format)
|
||||
return self.query(path, "delete", **params)
|
||||
return await self.query(path, "delete", **params)
|
||||
|
||||
def entries_exists(self, url, urls=''):
|
||||
async def entries_exists(self, url, urls=''):
|
||||
"""
|
||||
GET /api/entries/exists.{_format}
|
||||
|
||||
@@ -286,14 +332,16 @@ class Wallabag(object):
|
||||
|
||||
:return result
|
||||
"""
|
||||
params = {'url': url,
|
||||
params = {'access_token': self.token,
|
||||
'url': url,
|
||||
'urls': urls}
|
||||
|
||||
path = '/api/entries/exists.{ext}'.format(ext=self.format)
|
||||
return self.query(path, "get", **params)
|
||||
return await self.query(path, "get", **params)
|
||||
|
||||
# TAGS
|
||||
def get_entry_tags(self, entry):
|
||||
|
||||
async def get_entry_tags(self, entry):
|
||||
"""
|
||||
GET /api/entries/{entry}/tags.{_format}
|
||||
|
||||
@@ -305,9 +353,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/entries/{entry}/tags.{ext}'.format(
|
||||
entry=entry, ext=self.format)
|
||||
return self.query(url, "get", **params)
|
||||
return await self.query(url, "get", **params)
|
||||
|
||||
def post_entry_tags(self, entry, tags):
|
||||
async def post_entry_tags(self, entry, tags):
|
||||
"""
|
||||
POST /api/entries/{entry}/tags.{_format}
|
||||
|
||||
@@ -318,13 +366,13 @@ class Wallabag(object):
|
||||
:return result
|
||||
"""
|
||||
params = {'access_token': self.token, 'tags': []}
|
||||
if isinstance(tags, list):
|
||||
params['tags'] = tags
|
||||
if len(tags) > 0 and ',' in tags:
|
||||
params['tags'] = tags.split(',')
|
||||
path = '/api/entries/{entry}/tags.{ext}'.format(
|
||||
entry=entry, ext=self.format)
|
||||
return self.query(path, "post", **params)
|
||||
return await self.query(path, "post", **params)
|
||||
|
||||
def delete_entry_tag(self, entry, tag):
|
||||
async def delete_entry_tag(self, entry, tag):
|
||||
"""
|
||||
DELETE /api/entries/{entry}/tags/{tag}.{_format}
|
||||
|
||||
@@ -337,9 +385,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/entries/{entry}/tags/{tag}.{ext}'.format(
|
||||
entry=entry, tag=tag, ext=self.format)
|
||||
return self.query(url, "delete", **params)
|
||||
return await self.query(url, "delete", **params)
|
||||
|
||||
def get_tags(self):
|
||||
async def get_tags(self):
|
||||
"""
|
||||
GET /api/tags.{_format}
|
||||
|
||||
@@ -349,9 +397,9 @@ class Wallabag(object):
|
||||
"""
|
||||
params = {'access_token': self.token}
|
||||
path = '/api/tags.{ext}'.format(ext=self.format)
|
||||
return self.query(path, "get", **params)
|
||||
return await self.query(path, "get", **params)
|
||||
|
||||
def delete_tag(self, tag):
|
||||
async def delete_tag(self, tag):
|
||||
"""
|
||||
DELETE /api/tags/{tag}.{_format}
|
||||
|
||||
@@ -362,9 +410,9 @@ class Wallabag(object):
|
||||
"""
|
||||
path = '/api/tags/{tag}.{ext}'.format(tag=tag, ext=self.format)
|
||||
params = {'access_token': self.token}
|
||||
return self.query(path, "delete", **params)
|
||||
return await self.query(path, "delete", **params)
|
||||
|
||||
def delete_tag_label(self, tag):
|
||||
async def delete_tag_label(self, tag):
|
||||
"""
|
||||
DELETE /api/tag/label.{_format}
|
||||
|
||||
@@ -376,9 +424,9 @@ class Wallabag(object):
|
||||
path = '/api/tag/label.{ext}'.format(ext=self.format)
|
||||
params = {'access_token': self.token,
|
||||
'tag': tag}
|
||||
return self.query(path, "delete", **params)
|
||||
return await self.query(path, "delete", **params)
|
||||
|
||||
def delete_tags_label(self, tags):
|
||||
async def delete_tags_label(self, tags):
|
||||
"""
|
||||
DELETE /api/tags/label.{_format}
|
||||
|
||||
@@ -390,10 +438,10 @@ class Wallabag(object):
|
||||
path = '/api/tag/label.{ext}'.format(ext=self.format)
|
||||
params = {'access_token': self.token,
|
||||
'tags': tags}
|
||||
return self.query(path, "delete", **params)
|
||||
return await self.query(path, "delete", **params)
|
||||
|
||||
# ANNOTATIONS
|
||||
def delete_annotations(self, annotation):
|
||||
async def delete_annotations(self, annotation):
|
||||
"""
|
||||
DELETE /api/annotations/{annotation}.{_format}
|
||||
|
||||
@@ -407,9 +455,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/annotations/{annotation}.{ext}'.format(
|
||||
annotation=annotation, ext=self.format)
|
||||
return self.query(url, "delete", **params)
|
||||
return await self.query(url, "delete", **params)
|
||||
|
||||
def put_annotations(self, annotation):
|
||||
async def put_annotations(self, annotation):
|
||||
"""
|
||||
PUT /api/annotations/{annotation}.{_format}
|
||||
|
||||
@@ -423,9 +471,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/annotations/{annotation}.{ext}'.format(
|
||||
annotation=annotation, ext=self.format)
|
||||
return self.query(url, "put", **params)
|
||||
return await self.query(url, "put", **params)
|
||||
|
||||
def get_annotations(self, entry):
|
||||
async def get_annotations(self, entry):
|
||||
"""
|
||||
GET /api/annotations/{entry}.{_format}
|
||||
|
||||
@@ -439,9 +487,9 @@ class Wallabag(object):
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/annotations/{entry}.{ext}'.format(entry=entry,
|
||||
ext=self.format)
|
||||
return self.query(url, "get", **params)
|
||||
return await self.query(url, "get", **params)
|
||||
|
||||
def post_annotations(self, entry, **kwargs):
|
||||
async def post_annotations(self, entry, **kwargs):
|
||||
"""
|
||||
POST /api/annotations/{entry}.{_format}
|
||||
|
||||
@@ -464,11 +512,11 @@ class Wallabag(object):
|
||||
|
||||
url = '/api/annotations/{entry}.{ext}'.format(entry=entry,
|
||||
ext=self.format)
|
||||
return self.query(url, "post", **params)
|
||||
return await self.query(url, "post", **params)
|
||||
|
||||
# VERSION
|
||||
@property
|
||||
def version(self):
|
||||
async def version(self):
|
||||
"""
|
||||
GET /api/version.{_format}
|
||||
|
||||
@@ -478,10 +526,10 @@ class Wallabag(object):
|
||||
"""
|
||||
params = {'access_token': self.token}
|
||||
url = '/api/version.{ext}'.format(ext=self.format)
|
||||
return self.query(url, "get", **params)
|
||||
return await self.query(url, "get", **params)
|
||||
|
||||
@classmethod
|
||||
def get_token(cls, host, **params):
|
||||
async def get_token(cls, host, **params):
|
||||
"""
|
||||
POST /oauth/v2/token
|
||||
|
||||
@@ -500,6 +548,7 @@ class Wallabag(object):
|
||||
"""
|
||||
params['grant_type'] = "password"
|
||||
path = "/oauth/v2/token"
|
||||
resp = requests.post(host + path, data=params)
|
||||
data = cls.handle_json_response(resp)
|
||||
return data.get('access_token')
|
||||
async with aiohttp.ClientSession() as sess:
|
||||
async with sess.post(host + path, data=params) as resp:
|
||||
data = await cls.handle_json_response(resp)
|
||||
return data.get("access_token")
|
||||
|
||||
@@ -5,7 +5,7 @@ from wallabag import Wallabag
|
||||
|
||||
class TestWallabag(unittest.TestCase):
|
||||
|
||||
host = 'http://bag.foxmask'
|
||||
host = 'http://localhost:8000'
|
||||
client_id = ''
|
||||
client_secret = ''
|
||||
token = ''
|
||||
@@ -20,18 +20,20 @@ class TestWallabag(unittest.TestCase):
|
||||
|
||||
def test_get_token(self):
|
||||
params = {"grant_type": "password",
|
||||
"client_id": '1_3to3042y05gk8g4wcsk40w40k8kk00s04gwcoo4sows8wskcg0',
|
||||
"client_secret": 'ift9k07vd20ccg4ocosg0cw4kkgk4o8080848scwg0oosowow',
|
||||
"username": 'foxmask',
|
||||
"password": 'ratatab00m'}
|
||||
|
||||
"client_id":
|
||||
'1_4wqe1riwt0qoks844kwc4go08koogkgk88go4cckkwg0408kcg',
|
||||
"client_secret": '4mzw3qwi1xyc0cks4k80s4c8kco40wwkkkw0g40kwk4o4c44co',
|
||||
"username": 'wallabag',
|
||||
"password": 'wallabag'}
|
||||
print(self.host)
|
||||
data = Wallabag.get_token(host=self.host, **params)
|
||||
print(data)
|
||||
self.assertTrue(isinstance(data, str), True)
|
||||
return data
|
||||
|
||||
def create_entry(self):
|
||||
title = 'foobar title'
|
||||
url = 'https://trigger-happy.eu/'
|
||||
url = 'https://smcomm.trigger-happy.eu/'
|
||||
tags = ['foo', 'bar']
|
||||
starred = 0
|
||||
archive = 0
|
||||
@@ -75,6 +77,7 @@ class TestWallabag(unittest.TestCase):
|
||||
params = {'title': 'I change the title',
|
||||
'archive': 0,
|
||||
'tags': ["bimbo", "pipo"],
|
||||
'order': 'asc',
|
||||
'star': 0,
|
||||
'delete': 0}
|
||||
self.assertTrue(isinstance(entry, int), True)
|
||||
@@ -96,6 +99,16 @@ class TestWallabag(unittest.TestCase):
|
||||
data = self.w.post_entry_tags(entry, tags)
|
||||
self.assertTrue(data, True)
|
||||
|
||||
"""
|
||||
def test_delete_entry_tag(self):
|
||||
entry = self.create_entry()
|
||||
tag = 'bar'
|
||||
self.assertTrue(isinstance(entry['id'], int), True)
|
||||
self.assertTrue(isinstance(tag, str), True)
|
||||
resp = self.w.delete_entry_tag(entry['id'], tag)
|
||||
self.assertTrue(resp, True)
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user