Closed ghost closed 5 years ago
Hi @emporeso2,
Here is an example script to post a new entry to a Shaarli instance using the Python client:
#!/usr/bin/env python3
"""Post a link to a Shaarli instance"""
from shaarli_client.client import ShaarliV1Client
def main():
client = ShaarliV1Client(
'https://shaarli.domain.tld',
'apiS3cr3t'
)
client.post_link({
'description': '',
'private': False,
'tags': ['iot', 'automation'],
'title': 'Open source home automation',
'url': 'https://www.home-assistant.io/',
})
if __name__ == '__main__':
main()
Note that you will need to install the client from sources until a new release is published on PyPI (#39):
$ pip install git+https://github.com/shaarli/python-shaarli-client.git
I'am ok with your example but what about using the cli ! to add a tag or multiple tags with the url ? shaarli post-link --url http://myurl add-tag mytag1 mytag2
I'am ok with your example but what about using the cli !
You did not mention this in your issue, and given CLI usage is both:
then I assumed you asked for an example on how to use the client in a Python script or program.
The CLI is your best friend here!
$ shaarli -h
usage: shaarli [-h] [-c CONFIG] [-i INSTANCE] [-u URL] [-s SECRET]
[-f {json,pprint,text}] [-o OUTFILE]
{get-info,get-links,post-link,put-link,get-tags,get-tag,put-tag,delete-tag}
...
positional arguments:
{get-info,get-links,post-link,put-link,get-tags,get-tag,put-tag,delete-tag}
REST API endpoint
get-info Get information about this instance
get-links Get a collection of links ordered by creation date
post-link Create a new link or note
put-link Update an existing link or note
get-tags Get all tags
get-tag Get a single tag
put-tag Rename an existing tag
delete-tag Delete a tag from every link where it is used
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Configuration file
-i INSTANCE, --instance INSTANCE
Shaarli instance (configuration alias)
-u URL, --url URL Shaarli instance URL
-s SECRET, --secret SECRET
API secret
-f {json,pprint,text}, --format {json,pprint,text}
Output formatting
-o OUTFILE, --outfile OUTFILE
File to save the program output to
$ shaarli post-link -h
usage: shaarli post-link [-h] [--description DESCRIPTION [DESCRIPTION ...]]
[--private] [--tags TAGS [TAGS ...]]
[--title TITLE [TITLE ...]] [--url URL]
optional arguments:
-h, --help show this help message and exit
--description DESCRIPTION [DESCRIPTION ...]
Link description
--private Link visibility
--tags TAGS [TAGS ...]
List of tags associated with the link
--title TITLE [TITLE ...]
Link title
--url URL Link URL
Here's an example of POSTing a new entry on my development instance.
First the configuration, located in ~/.config/shaarli/client.ini
(replace values according to your own setup):
[shaarli]
url = https://shaarli.mydomain.net
secret = somesecretyouneednotknow
Then the actual command:
$ shaarli post-link --url https://debian.org --tags debian linux --title "Debian"
{
"created": "2019-01-23T21:26:09+00:00",
"description": "",
"id": 3785,
"private": false,
"shorturl": "Opr53w",
"tags": [
"debian",
"linux"
],
"title": "Debian",
"updated": "",
"url": "https://debian.org"
}
Hope this helps! ;-)
Yes great you save my day , my bad .
Great thanks.
Hello all, after reading the doc , is it possible to add a link with his tag in one line ?