Skip to content

Commit

Permalink
install pyrlottie by default/ regardless
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Aug 26, 2024
1 parent c19b2e4 commit bceec71
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 98 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All major and minor version changes will be documented in this file. Details of
patch-level version changes can be found in [commit messages](../../commits/master).

## 2024.1.3 - 2024/08/26

- be opinionated and install `pyrlottie` by default/ regardless
- clearly notify user if backend is not installed

## 2024.1.2 - 2024/03/25

- revert 'fix'
Expand Down
15 changes: 14 additions & 1 deletion documentation/reference/tstickers/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@
- [Cli](#cli)
- [cli](#cli)
- [is_library_installed](#is_library_installed)

## cli

[Show source in cli.py:17](../../../tstickers/cli.py#L17)
[Show source in cli.py:22](../../../tstickers/cli.py#L22)

Cli entry point.

#### Signature

```python
def cli() -> None: ...
```



## is_library_installed

[Show source in cli.py:18](../../../tstickers/cli.py#L18)

#### Signature

```python
def is_library_installed(library_name: str) -> bool: ...
```
84 changes: 8 additions & 76 deletions documentation/tutorials/README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,12 @@
<!-- omit in toc -->
# Tutorial

See below for a step-by-step tutorial on how to use TStickers
# TStickers Tutorials and User Guides

- [Step 1 - Send a message to @BotFather](#step-1---send-a-message-to-botfather)
- [Step 2 - Create a file called 'env'](#step-2---create-a-file-called-env)
- [Step 3 - Get the URL of the telegram sticker pack(s)](#step-3---get-the-url-of-the-telegram-sticker-packs)
- [Option 1 - Use a browser and search for the pack](#option-1---use-a-browser-and-search-for-the-pack)
- [Option 2 - Use telegram](#option-2---use-telegram)
- [Step 4 - Use TStickers](#step-4---use-tstickers)
Welcome to the TStickers tutorials. This section provides a handful of tutorials
to help you get started with TStickers and make the most of its features.

## Step 1 - Send a message to @BotFather
## Resource Table

1. You must have a telegram account to use this
2. Send a message to @BotFather to get started.
3. Send a message containing `/newbot`
4. Send a message containing the name of the bot e.g. `/test`
5. Send a message containing the username of the bot e.g. `/test_bot`
6. @BotFather will send a message with the token

<img src="assets/step1.png" alt="Step 1" width="600">

## Step 2 - Create a file called 'env'

Create a file called 'env' (or env.txt) and paste your token from part 1.

e.g. `env.txt`

```txt
14************
```

## Step 3 - Get the URL of the telegram sticker pack(s)

### Option 1 - Use a browser and search for the pack

1. Use a browser and search for the pack e.g. `telegram donut the dog`

<img src="assets/step3_0.png" alt="Step 3: Part 1" width="300">

2. Click on the link
3. Copy the url: e.g. `https://t.me/addstickers/DonutTheDog`

### Option 2 - Use telegram

1. Open telegram, find the desired sticker pack and share the pack (on mobile pick copy link). An example of sharing a pack is below

<img src="assets/step3_1.png" alt="Step 3: Part 2" width="300">

2. Click on share stickers/ link - this will copy the url: e.g. `https://t.me/addstickers/DonutTheDog`

## Step 4 - Use TStickers

- Run the program `python -m tstickers`
- Enter the URL of the sticker pack
- Get the output in the `downloads` folder.

```bash
$ tstickers
Enter sticker_set url (leave blank to stop): https://t.me/addstickers/DonutTheDog
Enter sticker_set url (leave blank to stop):
INFO | ============================================================
INFO | Starting to scrape "DonutTheDog" ..
INFO | Time taken to scrape 31 stickers - 0.044s
INFO |
INFO | ------------------------------------------------------------
INFO | Starting download of "donutthedog" into downloads\donutthedog
INFO | Time taken to download 31 stickers - 0.157s
INFO |
INFO | ------------------------------------------------------------
INFO | -> Cache miss for DonutTheDog!
INFO | Converting stickers "DonutTheDog"...
INFO | Time taken to convert 31 stickers (tgs) - 60.970s
INFO |
INFO | Time taken to convert 31 stickers (webp) - 0.447s
INFO |
INFO | Time taken to convert 62 stickers (total) - 61.434s
INFO |
```
| Guide | Description | Link |
|-----------------------|---------------------|---------------------------------------|
| **getting-started.md** | This guide will walk you through the initial setup of TStickers, including installation and basic usage. | [View getting-started.md](./getting-started.md) |
| **backends.md** | Learn about the different backend options available with TStickers. | [View backends.md](./backends.md) |
80 changes: 80 additions & 0 deletions documentation/tutorials/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!-- omit in toc -->
# Tutorial

See below for a step-by-step tutorial on how to use TStickers

- [Step 1 - Send a message to @BotFather](#step-1---send-a-message-to-botfather)
- [Step 2 - Create a file called 'env'](#step-2---create-a-file-called-env)
- [Step 3 - Get the URL of the telegram sticker pack(s)](#step-3---get-the-url-of-the-telegram-sticker-packs)
- [Option 1 - Use a browser and search for the pack](#option-1---use-a-browser-and-search-for-the-pack)
- [Option 2 - Use telegram](#option-2---use-telegram)
- [Step 4 - Use TStickers](#step-4---use-tstickers)

## Step 1 - Send a message to @BotFather

1. You must have a telegram account to use this
2. Send a message to @BotFather to get started.
3. Send a message containing `/newbot`
4. Send a message containing the name of the bot e.g. `/test`
5. Send a message containing the username of the bot e.g. `/test_bot`
6. @BotFather will send a message with the token

<img src="assets/step1.png" alt="Step 1" width="600">

## Step 2 - Create a file called 'env'

Create a file called 'env' (or env.txt) and paste your token from part 1.

e.g. `env.txt`

```txt
14************
```

## Step 3 - Get the URL of the telegram sticker pack(s)

### Option 1 - Use a browser and search for the pack

1. Use a browser and search for the pack e.g. `telegram donut the dog`

<img src="assets/step3_0.png" alt="Step 3: Part 1" width="300">

2. Click on the link
3. Copy the url: e.g. `https://t.me/addstickers/DonutTheDog`

### Option 2 - Use telegram

1. Open telegram, find the desired sticker pack and share the pack (on mobile pick copy link). An example of sharing a pack is below

<img src="assets/step3_1.png" alt="Step 3: Part 2" width="300">

2. Click on share stickers/ link - this will copy the url: e.g. `https://t.me/addstickers/DonutTheDog`

## Step 4 - Use TStickers

- Run the program `python -m tstickers`
- Enter the URL of the sticker pack
- Get the output in the `downloads` folder.

```bash
$ tstickers
Enter sticker_set url (leave blank to stop): https://t.me/addstickers/DonutTheDog
Enter sticker_set url (leave blank to stop):
INFO | ============================================================
INFO | Starting to scrape "DonutTheDog" ..
INFO | Time taken to scrape 31 stickers - 0.044s
INFO |
INFO | ------------------------------------------------------------
INFO | Starting download of "donutthedog" into downloads\donutthedog
INFO | Time taken to download 31 stickers - 0.157s
INFO |
INFO | ------------------------------------------------------------
INFO | -> Cache miss for DonutTheDog!
INFO | Converting stickers "DonutTheDog"...
INFO | Time taken to convert 31 stickers (tgs) - 60.970s
INFO |
INFO | Time taken to convert 31 stickers (webp) - 0.447s
INFO |
INFO | Time taken to convert 62 stickers (total) - 61.434s
INFO |
```
5 changes: 1 addition & 4 deletions move_webp_stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

source_dir = Path("./downloads")

packnames = [
name.name for name in source_dir.iterdir() if name.is_dir()
]
packnames = [name.name for name in source_dir.iterdir() if name.is_dir()]

for packname in packnames:
source_path = source_dir / packname / "webp"
dest_path = Path("./sorted") / packname


print(packname)

if not dest_path.exists():
Expand Down
26 changes: 13 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tstickers"
version = "2024.1.2"
version = "2024.1.3"
license = "mit"
description = "Download sticker packs from Telegram"
authors = ["FredHappyface"]
Expand All @@ -22,12 +22,12 @@ readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
requests = "<3,>=2.31.0"
Pillow = "<11,>=10.2.0"
emoji = "<3,>=2.10.1"
requests-cache = "<2,>=1.2.0"
rlottie-python = { version = "<2,>=1.3.3", optional = true }
pyrlottie = { version = "<2026,>=2024.0.1", optional = true }
requests = "<3,>=2.32.3"
Pillow = "<11,>=10.4.0"
emoji = "<3,>=2.12.1"
requests-cache = "<2,>=1.2.1"
rlottie-python = { version = "<2,>=1.3.6", optional = true }
pyrlottie = "<2026,>=2024.0.1"
loguru = "<2,>=0.7.2"

[tool.poetry.scripts]
Expand Down Expand Up @@ -56,14 +56,14 @@ target-version = "py38"
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN101", # type annotation for self in method
"COM812", # enforce trailing comma
"D2", # pydocstyle formatting
"ANN101", # type annotation for self in method
"COM812", # enforce trailing comma
"D2", # pydocstyle formatting
"ISC001",
"N", # pep8 naming
"N", # pep8 naming
"PLR09", # pylint refactor too many
"TCH", # type check blocks
"W191" # ignore this to allow tabs
"TCH", # type check blocks
"W191", # ignore this to allow tabs
]
fixable = ["ALL"]

Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Pillow<11,>=10.2.0
emoji<3,>=2.10.1
Pillow<11,>=10.4.0
emoji<3,>=2.12.1
loguru<2,>=0.7.2
requests-cache<2,>=1.2.0
requests<3,>=2.31.0
pyrlottie<2026,>=2024.0.1
requests-cache<2,>=1.2.1
requests<3,>=2.32.3
12 changes: 12 additions & 0 deletions tstickers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import functools
import importlib.util
import operator
from pathlib import Path
from sys import exit as sysexit
Expand All @@ -14,6 +15,10 @@
from tstickers.downloader import StickerDownloader


def is_library_installed(library_name: str) -> bool:
return importlib.util.find_spec(library_name) is not None


def cli() -> None: # pragma: no cover
"""Cli entry point."""
parser = argparse.ArgumentParser("Welcome to TStickers, providing all of your sticker needs")
Expand Down Expand Up @@ -68,6 +73,13 @@ def cli() -> None: # pragma: no cover
"message to @BotFather to get started"
)
sysexit(1)
# Get the backend
backend = args.backend

if not is_library_installed(backend):
logger.error(f'!! {backend} is not installed! Install with "pip install {backend}"')
sysexit(2)

# Get the packs

packs = []
Expand Down

0 comments on commit bceec71

Please sign in to comment.