diff --git a/README.md b/README.md index 5dafa78..6d04311 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,68 @@ -[![Discord](https://img.shields.io/discord/899171661457293343?color=7289da&label=discord&logo=discord&logoColor=white&style=flat)](https://discord.gg/wXy6m2X8wY) -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1eee626c47fa4e6fb8b1ed3efdd3e518)](https://app.codacy.com/gh/cssnr/zipline-cli/dashboard) -[![PyPI](https://img.shields.io/pypi/v/zipline-cli)](https://pypi.org/project/zipline-cli/) -[![](https://repository-images.githubusercontent.com/661201286/8dfadbc8-94c0-4eaa-88bd-7ee351859510)](https://zipline.diced.tech/) +[![Discord](https://img.shields.io/discord/899171661457293343?logo=discord&logoColor=white&label=Discord)](https://discord.gg/wXy6m2X8wY) +[![PyPI](https://img.shields.io/github/issues-raw/cssnr/zipline-cli?logo=github&logoColor=white&label=Issues)](https://github.com/cssnr/zipline-cli/issues) +[![Codacy Badge](https://img.shields.io/codacy/grade/1eee626c47fa4e6fb8b1ed3efdd3e518?logo=codacy&logoColor=white&label=Codacy)](https://app.codacy.com/gh/cssnr/zipline-cli/dashboard) +[![PyPI](https://img.shields.io/pypi/v/zipline-cli?logo=python&logoColor=white&label=PyPi)](https://pypi.org/project/zipline-cli/) +[![](https://repository-images.githubusercontent.com/661201286/8dfadbc8-94c0-4eaa-88bd-7ee351859510)](https://github.com/cssnr/zipline-cli) # Zipline CLI Python 3 CLI Uploader for Zipline. +Zipline CLI is currently functional and **Under Active Development**. +Please open a [Feature Request](https://github.com/cssnr/zipline-cli/discussions/new?category=feature-requests) +for new features and submit an [Issue](https://github.com/cssnr/zipline-cli/issues) +for any bugs you find. -* Zipline: [https://zipline.diced.tech/](https://zipline.diced.tech/) +* Zipline Docs: [https://zipline.diced.tech/](https://zipline.diced.tech/) -This is currently a **WIP** and not complete, but has some useful functions. +## Table of Contents + +* [Quick Start](#quick-start) +* [Install](#install) +* [CLI Usage](#cli-usage) +* [Environment Variables](#environment-variables) +* [Python API Reference](#python-api-reference) +* [Additional Information](#additional-information) + +## Quick Start + +```bash +python3 -m pip install zipline-cli +zipline --setup +``` ## Install From PyPi using pip: -```text +```bash python3 -m pip install zipline-cli ``` From GitHub using pip: -```text +```bash python3 -m pip install git+https://github.com/cssnr/zipline-cli.git ``` +From Source using pip: +```bash +git clone https://github.com/cssnr/zipline-cli.git +python3 -m pip install -e zipline-cli +``` + From Source using setuptools: -```text +```bash git clone https://github.com/cssnr/zipline-cli.git cd zipline-cli python3 setup.py install ``` -Uninstall: -```text +### Uninstall + +To completely remove from any above install methods: +```bash python3 -m pip uninstall zipline-cli ``` ## CLI Usage -You will need a Zipline URL and Token to use the utility. - Setup Zipline URL and Token: ```bash zipline --setup @@ -48,22 +73,27 @@ Upload a File: zipline test.txt ``` +Upload Multiple Files: +```bash +zipline file1.txt file2.txt +``` + Create Text File from Input ```bash cat test.txt | zipline ``` -Create Text File from Text +Create Text File from Clipboard ```bash zipline -# type or paste contents followed by Ctrl+D (Ctrl+Z on Windows) +# Paste or Type contents, followed by a newline, then Ctrl+D (Ctrl+Z on Windows) ``` ## Environment Variables Environment Variables are stored in the `.zipline` file in your home directory. -* Location: `~/.zipline` +* Location: `~/.zipline` or `$HOME/.zipline` | Variable | Description | |----------------|-----------------------------------------------------------------------------| @@ -72,13 +102,14 @@ Environment Variables are stored in the `.zipline` file in your home directory. | ZIPLINE_EMBED | Set this enable Embed on your uploads | | ZIPLINE_EXPIRE | See: https://zipline.diced.tech/docs/guides/upload-options#image-expiration | -You may also override them by exporting the variables in your current environment. +You may override them by exporting the variables in your current environment +or using the corresponding command line arguments. See `-h` for more info. -## API Reference +## Python API Reference -Initialize the class with your Zipline URL. -Everything else is a header passed as a kwarg. -The API does not yet support environment variables. +Initialize the class with your Zipline URL. +Everything else is a header passed as a kwarg. +The API does not yet support environment variables. Zipline Token/Authorization is a header kwarg and can be passed as follows: ```python @@ -97,5 +128,10 @@ print(url) ## Additional Information -> If you have more questions, concerns, or comments? -> Join our [Discord](https://discord.gg/wXy6m2X8wY) for more information... +Still have questions, concerns, or comments? + +* [Feature Requests](https://github.com/cssnr/zipline-cli/discussions/categories/feature-requests) +* [Helpdesk Q&A](https://github.com/cssnr/zipline-cli/discussions/categories/helpdesk-q-a) +* [Discord](https://discord.gg/wXy6m2X8wY) + +> Zipline Guide: Hit That Fresh Nar Nar: [youtube.com/watch?v=bJHYo2aGWgE](https://www.youtube.com/watch?v=bJHYo2aGWgE) diff --git a/build.ps1 b/build.ps1 index ca14c43..2aaac4a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,9 +1,19 @@ $ErrorActionPreference = "Stop" -$egg_dir = "zipline_cli.egg-info" +#if (-Not $args[0]) { +# Write-Output "Specify version number with format: x.x.x" +# exit +#} +#$env:ZIPLINE_VERSION = $args[0] +#Write-Output "Version: $env:ZIPLINE_VERSION" + +$egg_dir = ".\zipline_cli.egg-info" if (Test-Path $egg_dir) { Remove-Item -Force -Recurse $egg_dir } +if (Test-Path ".\__pycache__") { + Remove-Item -Force -Recurse ".\__pycache__" +} if (Test-Path ".\build") { Remove-Item -Force -Recurse ".\build" } @@ -11,6 +21,11 @@ if (Test-Path ".\dist") { Remove-Item -Force -Recurse ".\dist" } +if ($args[0] -eq "clean") { + Write-Output "Clean Only Done. Not Building." + exit +} + python.exe -m build Write-Output "Success." diff --git a/setup.py b/setup.py index de4c3ee..ea6a63e 100644 --- a/setup.py +++ b/setup.py @@ -5,8 +5,8 @@ long_description = f.read() setup( + version='0.1.3', name='zipline-cli', - version='0.1.2', description='Python 3 CLI for Zipline', long_description=long_description, long_description_content_type="text/markdown", diff --git a/zipline.py b/zipline.py index e1b98a2..efa1d5c 100644 --- a/zipline.py +++ b/zipline.py @@ -12,10 +12,37 @@ from typing import Any, Dict, List, Optional, TextIO +class ZipURL(object): + """ + Zipline URL Object + :param file_url: str: Zipline File Display URL + """ + + __slots__ = ['url', 'raw'] + + def __init__(self, file_url: str): + self.url: str = file_url + self.raw: str = self._get_raw(file_url) + + def __repr__(self): + return f'' + + def __str__(self): + return self.url + + @staticmethod + def _get_raw(url: str) -> str: + try: + s = url.split('/', 4) + return f"{s[0]}//{s[2]}/r/{s[4]}" + except Exception: + return '' + + class Zipline(object): """ Zipline Python API - :param url: str: Zipline URL + :param base_url: str: Zipline URL :param kwargs: Zipline Headers """ allowed_headers = ['format', 'image_compression_percent', 'expires_at', @@ -23,19 +50,19 @@ class Zipline(object): 'authorization', 'no_json', 'x_zipline_filename', 'original_name', 'override_domain'] - def __init__(self, zipline_url: str, **kwargs): - self.zipline_url: str = zipline_url.rstrip('/') - self.headers: Dict[str, str] = {} + def __init__(self, base_url: str, **kwargs): + self.base_url: str = base_url.rstrip('/') + self._headers: Dict[str, str] = {} for header, value in kwargs.items(): if header.lower() not in self.allowed_headers: continue if value is None: continue key = header.replace('_', '-').title() - self.headers[key] = str(value) + self._headers[key] = str(value) def send_file(self, file_name: str, file_object: TextIO, - overrides: Optional[dict] = None) -> str: + overrides: Optional[dict] = None) -> ZipURL: """ Send File to Zipline :param file_name: str: Name of File for files tuple @@ -43,15 +70,27 @@ def send_file(self, file_name: str, file_object: TextIO, :param overrides: dict: Header Overrides :return: str: File URL """ - url = self.zipline_url + '/api/upload' + url = self.base_url + '/api/upload' files = {'file': (file_name, file_object)} - headers = self.headers | overrides if overrides else self.headers + headers = self._headers | overrides if overrides else self._headers r = requests.post(url, headers=headers, files=files) r.raise_for_status() - return r.json()['files'][0] + return ZipURL(r.json()['files'][0]) # return f'https://example.com/dummy/{file_name}' +def format_output(filename: str, url: ZipURL) -> str: + """ + Format URL Output + :param filename: str: Original or File Name + :param url: ZipURL: ZipURL to Format + :return: str: Formatted Output + """ + if url.raw: + return f'{filename}\n{url}\n{url.raw}' + return f'{filename}\n{url}' + + def gen_rand(length: Optional[int] = 4) -> str: """ Generate Random Streng at Given length @@ -153,22 +192,22 @@ def main() -> None: content: str = sys.stdin.read().rstrip('\n') + '\n' text_f: TextIO = io.StringIO(content) name = f'{gen_rand(8)}.txt' - url: str = zipline.send_file(name, text_f) - print(f'{name} -> {url}') + url: ZipURL = zipline.send_file(name, text_f) + print(format_output(name, url)) sys.exit(0) exit_code = 1 - for filename in args.files: - if not os.path.isfile(filename): - print(f'Warning: File Not Found: {filename}') + for name in args.files: + if not os.path.isfile(name): + print(f'Warning: File Not Found: {name}') continue - with open(filename) as f: + with open(name) as f: # name, ext = os.path.splitext(os.path.basename(filename)) # ext = f'.{ext}' if ext else '' # name = f'{name}-{gen_rand(8)}{ext}' # url: str = zipline.send_file(name, f) - url: str = zipline.send_file(filename, f) - print(f'{filename} -> {url}') + url: ZipURL = zipline.send_file(name, f) + print(format_output(name, url)) exit_code = 0 sys.exit(exit_code)