Skip to content

Commit

Permalink
Sample usage, return album id at creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chostakovitch committed Mar 4, 2022
1 parent 09c53ab commit b6b1434
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pydocstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Test NumpyDoc Style
run: |
cd pychee
pydocstyle --convention=numpy
pydocstyle --convention=numpy
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ The API is partially implemented and focused on photo management, _i.e._ only `A
Disclaimer : I usually suck at coding, so use with caution and at your own risks.
Tested with Lychee v4.3.4. The code probably won't be retrocompatible and should just work with the latest version.

## Example usage

A sample of common API calls :

```python
#!/usr/bin/env python
# coding=utf-8
from pychee import pychee

# Initialize instance
client = pychee.LycheeClient('https://pic.chosto.me')

# Login
client.login('login', 'password')

# Create a new album
album_name = 'test_name'
album_id = client.add_album(album_name)

# Add a photo in the created album
path_to_your_photo = '/your/path/photo.jpg'
with open(path_to_your_photo, 'rb') as f:
photo_id = client.add_photo(f, 'photo.jpg', album_id)

# Set uploaded photo public
client.set_photo_public(photo_id)

# Set licence of uploaded photo
client.set_photo_license(photo_id, 'CC0')

# Download an archive of the created album
output_path = '/tmp/photos.zip'
with(open(output_path, 'wb')) as f:
f.write(client.get_albums_archive([id]))

# Logout
client.logout()
```

## Documentation

Documentation is automatically published there : https://chostakovitch.github.io/pychee/index.html
28 changes: 14 additions & 14 deletions docsource/conf.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
"""
Configuration file for the Sphinx documentation builder.
# -- Path setup --------------------------------------------------------------
This file only contains a selection of the most common options. For a full
list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
-- Path setup --------------------------------------------------------------
If extensions (or modules to document with autodoc) are in another directory,
add these directories to sys.path here. If the directory is relative to the
documentation root, use os.path.abspath to make it absolute, like shown here.
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
"""

# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -54,4 +54,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
2 changes: 1 addition & 1 deletion pychee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# pychee: Client for Lychee, written in Python.
For additonal information, visit: [Lychee](https://github.com/LycheeOrg/Lychee).
"""
"""
15 changes: 8 additions & 7 deletions pychee/pychee.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List
from requests import Session

__version__ = '0.1.1'
__version__ = '0.1.2'

class LycheeForbidden(Exception):
"""Raised when the Lychee request is unauthorized."""
Expand Down Expand Up @@ -117,14 +117,16 @@ def get_public_album(self, album_id: str, password: str = 'rand') -> bool:
data = {'albumID': album_id, 'password': password}
return 'true' in self._session.post('Album::getPublic', data=data).text

def add_album(self, title: str, parent_id: str = "0") -> bool:
def add_album(self, title: str, parent_id: str = "0") -> str:
"""
Add a new Album with option parent.
Add a new Album with optional parent.
API won't work with empty parent_id, use 0 as in webapp for no parent.
Return the ID of the new image.
"""
data = {'title': title, 'parent_id': parent_id}
return 'true' in self._session.post('Album::add', data=data).text
return self._session.post('Album::add', data=data).text

def set_albums_title(self, album_ids: List[str], title: str) -> bool:
"""Change the title of the albums."""
Expand Down Expand Up @@ -263,7 +265,7 @@ def set_photos_tags(self, photo_ids: List[str], tags: List[str]) -> bool:
data = {'photoIDs': ','.join(photo_ids), 'tags': ','.join(tags)}
return 'true' in self._session.post('Photo::setTags', data=data).text

def add_photo(self, photo: bytes, photo_name: str, album_id: str) -> int:
def add_photo(self, photo: bytes, photo_name: str, album_id: str) -> str:
"""
Upload a photo into an album.
Expand All @@ -273,7 +275,7 @@ def add_photo(self, photo: bytes, photo_name: str, album_id: str) -> int:
"""
data = {'albumID': album_id}
files = {'0': (photo_name, photo)}
return int(self._session.post('Photo::add', data=data, files=files).text)
return self._session.post('Photo::add', data=data, files=files).text

def delete_photo(self, photo_ids: List[str]) -> bool:
"""Delete one or multiple photos."""
Expand Down Expand Up @@ -335,7 +337,6 @@ def share_with_users(self, user_ids: List[str], album_ids: List[str]) -> bool:
data = {
'UserIDs': ','.join(user_ids),
'albumIDs': ','.join(album_ids)}
print(data)
return 'true' in self._session.post('Sharing::Add', data=data).text

def delete_shares(self, share_ids: List[str]) -> bool:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Install pychee."""
from setuptools import setup
setup()

0 comments on commit b6b1434

Please sign in to comment.