From bc6080e832fcac5efef081097067a7e9489d933f Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 13 Mar 2023 11:33:30 +0100 Subject: [PATCH 1/2] Added venv guide to README --- README.md | 44 ++++++++++++++++++++++++-------------------- docs/config_venv.md | 1 - 2 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 docs/config_venv.md diff --git a/README.md b/README.md index 18e7acb..9da5b42 100644 --- a/README.md +++ b/README.md @@ -30,39 +30,44 @@ To make this bot run at first you need to have a Python interpreter, Photos API, 2. Install Photos API by following [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md) 2. Download the bot: - 1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you want to use git) - 2. `cd ./TelegramPoster` + 1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you want to use git) + 2. `cd TelegramPoster` -3. Install project's dependencies: +3. Create virtual environment [Optional]: + 1. Install virtualenv module: `pip install virtualenv` + 2. Create venv: `python -m venv env` + 3. Activate it using `source venv/bin/activate` on Linux, `venv\Scripts\activate.bat` in CMD or `venv\Scripts\Activate.ps1` in PowerShell. + +4. Install project's dependencies: `python -m pip install -r requirements.txt` - Without installing those - bot cannot work at all + Without installing those - bot cannot work at all. -4. Install optional dependencies [Not required]: +5. Install optional dependencies [Optional]: `python -m pip install -r requirements-optional.txt` - These are not required but can make the bot run a bit faster + These are not required but can make the bot run a bit faster. -5. Configure "bot" and "owner" with your favorite text editor: +6. Configure "bot" and "owner" with your favorite text editor: `nano config.json` You can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever. If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id). -6. Configure database and API: +7. Configure database and API: 1. Configure database: - 1. Change database host and port in keys `"database.host"` and `"database.port"`. For default local installation those will be `127.0.0.1` and `27017` respectively; - 2. Change database name to the one you like in `"database.name"`. It will be automatically created on start; + 1. Change database host and port in keys `"database.host"` and `"database.port"`. For default local installation those will be `127.0.0.1` and `27017` respectively + 2. Change database name to the one you like in `"database.name"`. It will be automatically created on start 3. If you've changed user and password to access the db, you should also change `"database.user"` and `"database.password"` keys, otherwise leave them `null` (default). 2. Configure Photos API: - 1. Change `"posting.api.address"` to the one your API servers uses; - 2. Run your bot using `python ./poster.py --create-user --create-album` to configure its new user and album. You can also use manual user and album creation described [in the wiki](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). You can also change username, password and album in`"posting.api"` to the user and album you have if you already have Photos API album and user set up. In that case you don't need to create a new one. + 1. Change `"posting.api.address"` to the one your API servers uses + 2. Run your bot using `python poster.py --create-user --create-album` to configure its new user and album. You can also use manual user and album creation described [in the wiki](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). You can also change username, password and album in`"posting.api"` to the user and album you have if you already have Photos API album and user set up. In that case you don't need to create a new one. -7. Add bot to the channel: +8. Add bot to the channel: To use your bot of course you need to have a channel or group otherwise makes no sense to have such a bot. [Here](https://stackoverflow.com/a/33497769) you can find a quick guide how to add your bot to a channel. After that simply set `"posting.channel"` to your channel's ID. -8. Configure posting time: +9. Configure posting time: To make your bot post random content you need to configure `"posting.time"` with a list of "DD:MM" formatted strings or use `"posting.interval"` formatted as "XdXhXmXs". To use interval instead of selected time set `"posting.use_interval"` to `true`. -9. Good to go, run it! - Make sure MongoDB and Photos API are running and use `python ./poster.py` to start it. +10. Good to go, run it! + Make sure MongoDB and Photos API are running and use `python poster.py` to start it. Or you can also use `.\start.bat` on Windows and `bash ./start.sh` on Linux. Additionally there are `loop.sh` and `loop.bat` available if you want your bot to start again after being stopped or after using `/reboot` command. @@ -77,13 +82,12 @@ Of course bot also has them. You can perform some actions with them. Examples: -* `python ./poster.py --create-user` -* `python ./poster.py --create-user --create-album` +* `python poster.py --create-user` +* `python poster.py --create-user --create-album` ## Tips and improvements -* It's better to use virtual environments in most of production cases so there's also [a tutorial how to put your bot into venv](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Virtual-Environment) and use it inside the virtual environment; -* You may also want to configure your bot to work as a systemd service instead. There's [a tutorial for that](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Service) in the wiki. +* You may want to configure your bot to work as a systemd service instead. There's [a tutorial for that](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Service) in the wiki. ## Localization diff --git a/docs/config_venv.md b/docs/config_venv.md deleted file mode 100644 index ecdabd1..0000000 --- a/docs/config_venv.md +++ /dev/null @@ -1 +0,0 @@ -# Configuring virtual environment From 87d2a2c6d35a97c756eb1b93b11be06400d44fe6 Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 13 Mar 2023 13:02:06 +0100 Subject: [PATCH 2/2] Improved README --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9da5b42..9949438 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ This bot is used for one and only task - post pictures from my personal archive. ## Dependencies -For now bot requires [MongoDB](https://www.mongodb.com) and [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI) in order to function properly. Use [MongoDB's installation manual](https://www.mongodb.com/docs/manual/installation) and [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md) to install install them. +* [Python 3.7+](https://www.python.org) (3.9+ recommended) +* [MongoDB](https://www.mongodb.com) +* [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI) + +Use [MongoDB's installation manual](https://www.mongodb.com/docs/manual/installation) and [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md). Please note that Photos API also requires MongoDB so it makes sense to install and configure Mongo first. @@ -26,47 +30,58 @@ To make this bot run at first you need to have a Python interpreter, Photos API, > it in scripts you will use (`loop.sh`, `loop.bat`, `start.sh` and `start.bat`). 1. Install Mongo and Photos API: + 1. Install MongoDB by following [official installation manual](https://www.mongodb.com/docs/manual/installation) 2. Install Photos API by following [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md) 2. Download the bot: - 1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you want to use git) + + 1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you're using git) 2. `cd TelegramPoster` 3. Create virtual environment [Optional]: + 1. Install virtualenv module: `pip install virtualenv` 2. Create venv: `python -m venv env` 3. Activate it using `source venv/bin/activate` on Linux, `venv\Scripts\activate.bat` in CMD or `venv\Scripts\Activate.ps1` in PowerShell. 4. Install project's dependencies: + `python -m pip install -r requirements.txt` Without installing those - bot cannot work at all. 5. Install optional dependencies [Optional]: + `python -m pip install -r requirements-optional.txt` These are not required but can make the bot run a bit faster. 6. Configure "bot" and "owner" with your favorite text editor: + `nano config.json` You can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever. If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id). 7. Configure database and API: + 1. Configure database: 1. Change database host and port in keys `"database.host"` and `"database.port"`. For default local installation those will be `127.0.0.1` and `27017` respectively 2. Change database name to the one you like in `"database.name"`. It will be automatically created on start 3. If you've changed user and password to access the db, you should also change `"database.user"` and `"database.password"` keys, otherwise leave them `null` (default). + 2. Configure Photos API: 1. Change `"posting.api.address"` to the one your API servers uses 2. Run your bot using `python poster.py --create-user --create-album` to configure its new user and album. You can also use manual user and album creation described [in the wiki](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). You can also change username, password and album in`"posting.api"` to the user and album you have if you already have Photos API album and user set up. In that case you don't need to create a new one. 8. Add bot to the channel: + To use your bot of course you need to have a channel or group otherwise makes no sense to have such a bot. [Here](https://stackoverflow.com/a/33497769) you can find a quick guide how to add your bot to a channel. After that simply set `"posting.channel"` to your channel's ID. 9. Configure posting time: + To make your bot post random content you need to configure `"posting.time"` with a list of "DD:MM" formatted strings or use `"posting.interval"` formatted as "XdXhXmXs". To use interval instead of selected time set `"posting.use_interval"` to `true`. 10. Good to go, run it! + Make sure MongoDB and Photos API are running and use `python poster.py` to start it. Or you can also use `.\start.bat` on Windows and `bash ./start.sh` on Linux. Additionally there are `loop.sh` and `loop.bat` available if you want your bot to start again after being stopped or after using `/reboot` command.