/neocitizen

Python client library for Neocities API.

Primary LanguagePythonApache License 2.0Apache-2.0

neocitizen: Python client library for Neocities API

pytest neocities PyPI Version Python Versions License Code style: black Imports: isort

Neocities is a web hosting service for static pages. This is a library that makes the Neocities API available from the CLI and Python.

Installation

neocitizen is available on PyPI:

$ pip install neocitizen

You can also use poetry to add it to a Python project.

$ poetry add neocitizen

CLI Examples

Upload the directory and check the result

$ export NEOCITIES_API_KEY=<your api key here>
$ neocitizen upload --dir=/path/to/dir
$ neocitizen list
dir0
dir0/file00.html
dir0/file01.html
dir1
dir1/dir10
dir1/dir10/file100.html
dir1/dir11
dir1/dir11/file110.html
dir1/file10.html
dir1/file11.html
index.html

Download

$ export NEOCITIES_API_KEY=<your api key here>
$ neocitizen download /path/to/save

Detailed usage

$ neocitizen --help
Usage: neocitizen [OPTIONS] COMMAND [ARGS]...

Options:
  --version        Show the version and exit.
  --key TEXT       API key. You can also use the environment variable NEOCITIES_API_KEY instead.
  --username TEXT  User name for authentication. You can also use the environment variable NEOCITIES_USERNAME instead.
  --password TEXT  Password for authentication. You can also use the environment variable NEOCITIES_PASSWORD instead.
  -v, --verbose    Verbose output.
  --help           Show this message and exit.

Commands:
  delete    Delete the files on your Neocities site.
  download  Download all the files on your Neocities site.
  info      Show information about your Neocities site.
  key       Show API key.
  list      Show file list your Neocities site.
  upload    Upload local data to your Neocities site.

Python Examples

Code: example.py

from neocitizen import NeocitiesApi

api = NeocitiesApi()
response = api.fetch_info()
for key, value in response["info"].items():
    print(f"{key}: {value}")

Run

$ export NEOCITIES_API_KEY=<your api key here>
$ python example.py
sitename: neocli-test
views: 268
hits: 483
created_at: Sun, 05 Dec 2021 12:13:28 -0000
last_updated: Sun, 19 Dec 2021 13:37:13 -0000
domain: None
tags: []
latest_ipfs_hash: None