Skip to content

Commit

Permalink
improve module/package
Browse files Browse the repository at this point in the history
  • Loading branch information
gpchelkin committed Feb 21, 2023
1 parent 63fe3cb commit 036cac1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 46 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ update:
poetry self lock
poetry self install --sync
poetry self update
poetry install --with main,dev,docs --sync
poetry run pip install --upgrade pip setuptools wheel
poetry update --with main,dev,docs
poetry export --only main --without-hashes -f requirements.txt -o requirements.txt
poetry export --only docs --without-hashes -f requirements.txt -o requirements-docs.txt
Expand All @@ -33,10 +35,10 @@ test: lint package

.PHONY: run_dev
run_dev:
ps -ef | grep '[s]cdlbot/scdlbot.py' | grep -v bash | awk '{print $$2}' | xargs --no-run-if-empty kill -15
ps -ef | grep '[s]cdlbot' | grep 'python' | grep -v 'bash' | awk '{print $$2}' | xargs --no-run-if-empty kill -15
set -o allexport; \
source .env-dev; \
poetry run python scdlbot/scdlbot.py
poetry run python scdlbot/__main__.py

.DEFAULT:
@cd docs && $(MAKE) $@
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: python -m scdlbot.scdlbot
worker: python -m scdlbot.scdlbot
web: python -m scdlbot
worker: python -m scdlbot
51 changes: 24 additions & 27 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,24 @@ Those should be available in your ``PATH``:
and `Linux <https://johnvansickle.com/ffmpeg/>`__ are recommended)
- `Heroku CLI <https://cli.heroku.com>`__ is recommended if you want to deploy to Heroku

Install / Update stable from `PyPI <https://pypi.org/project/scdlbot>`__ (recommended)
Install / Update stable build from `PyPI <https://pypi.org/project/scdlbot>`__ (recommended)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

::

pip3 install scdlbot --upgrade
pip install --upgrade scdlbot

...or get unstable from `Git source repository <https://github.com/gpchelkin/scdlbot>`__
...or get latest unstable build from `Git source repository <https://github.com/gpchelkin/scdlbot>`__
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

::

git clone https://github.com/gpchelkin/scdlbot.git
cd scdlbot
pip3 install --requirement requirements.txt
pip install --editable "./"

# Update:
git pull
pip3 install --requirement requirements.txt
# or just install directly from Git with pip:
pip install "scdlbot @ git+https://github.com/gpchelkin/scdlbot.git@master"


Configure Bot
Expand All @@ -134,12 +133,10 @@ config environment variables in it:

::

# If you've installed from PyPI - download sample config somewhere:
curl -o .env https://raw.githubusercontent.com/gpchelkin/scdlbot/master/.env.sample
# Skip if you've got Git source:
curl -o .env.sample https://raw.githubusercontent.com/gpchelkin/scdlbot/master/.env.sample

# If you've got Git source - just copy sample config:
cp .env.sample .env

# Use your favourite editor. Sample config is self-documented:
nano .env

Expand All @@ -150,43 +147,43 @@ Send the commands from respective filenames in ``telegram_settings`` dir to `@Bo
Disable privacy mode if you want bot to read and check every message in group for links.
Otherwise, it would work only for commands.

Running Locally or at Dedicated Server
Running Locally or on Dedicated Server
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Using `Heroku Local <https://devcenter.heroku.com/articles/heroku-local#run-your-app-locally-using-the-heroku-local-command-line-tool>`__ (preferred)
Using `Heroku Local <https://devcenter.heroku.com/articles/heroku-local#run-your-app-locally-using-the-heroku-local-command-line-tool>`__
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

You will need `Heroku CLI <https://cli.heroku.com/>`__ installed.

::

# If you've installed from PyPI - download Procfile first (otherwise already present in Git repository):
# Skip if you've got Git source:
curl -O https://raw.githubusercontent.com/gpchelkin/scdlbot/master/Procfile

# For long polling mode (when WEBHOOK_ENABLE=0):
# For long polling mode (if WEBHOOK_ENABLE="0"):
heroku local -e .env worker
# For webhook mode (when WEBHOOK_ENABLE=1):
# For webhook mode (if WEBHOOK_ENABLE="1"):
heroku local -e .env web

Using Python only
Using only Bash & Python
"""""""""""""""""

::

export $(grep -v '^#' .env | xargs)
python3 -m scdlbot.scdlbot
python -m scdlbot
# or in one line:
env $(grep -v '^#' .env | xargs) python3 -m scdlbot.scdlbot
env $(grep -v '^#' .env | xargs) python -m scdlbot

# If you've installed package from PyPI into the system,
# you can also replace 'python3 -m scdlbot.scdlbot' with only 'scdlbot'
# If you've installed package into your system Python,
# you can also replace 'python -m scdlbot' with just 'scdlbot'

Deploying to `Heroku <https://heroku.com/>`__
Deploying to `Heroku <https://www.heroku.com>`__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

|Deploy|

Register on Heroku, press the button above and
Register on Heroku, press the Deploy button above and
configure variables for deploying.
When app is deployed you **must** set only one dyno working on
"Resources" tab in your app settings depending on `which way of getting
Expand All @@ -198,8 +195,8 @@ Manually
""""""""

You can do the same as the button above but using `Heroku
CLI <https://cli.heroku.com/>`__, not as much of a fun. Assuming you are in
``scdlbot`` repository directory:
CLI <https://cli.heroku.com/>`__. Assuming you are in
``scdlbot`` Git repository directory:

::

Expand All @@ -213,10 +210,10 @@ CLI <https://cli.heroku.com/>`__, not as much of a fun. Assuming you are in
# Set config vars automatically from your local .env file:
heroku plugins:install heroku-config
heroku config:push --file=.env --app=myscdlbot
# Or set them manually like this:
# or set them manually like this:
heroku config:set TG_BOT_TOKEN="<TG_BOT_TOKEN>" TG_BOT_OWNER_CHAT_ID="<TG_BOT_OWNER_CHAT_ID>" ...
# Deploy app to Heroku:
#heroku git:remote --app=myscdlbot
#heroku git:remote --app=myscdlbot
git push heroku master

Then, if you want to use webhook, start web dyno and stop worker dyno:
Expand Down
20 changes: 12 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include = ["AUTHORS.rst", "CONTRIBUTING.md", "CHANGELOG.rst", "LICENSE", "README
#"Changelog" = "https://github.com/gpchelkin/scdlbot/blob/master/CHANGELOG.rst"

[tool.poetry.scripts]
scdlbot = "scdlbot.scdlbot:main"
scdlbot = "scdlbot.__main__:main"

[tool.poetry.dependencies]
python = "^3.9"
Expand All @@ -61,14 +61,14 @@ fake-useragent = "^1.1.1"

### For publishing to PyPI at release:
# https://github.com/yt-dlp/yt-dlp/wiki/Forks
yt-dlp = "2023.2.17"
#yt-dlp = "2023.2.17"
##youtube_dl = "2021.12.17"
##youtube-dlc = "2020.11.11.post3"
scdl = "2.7.3"
bandcamp-downloader = "0.0.13"

### For making it work better using latest git revision:
#yt-dlp = { git = "https://github.com/yt-dlp/yt-dlp.git", branch = "master" }
yt-dlp = { git = "https://github.com/yt-dlp/yt-dlp.git", branch = "master" }
##yt-dlp = { git = "https://github.com/pritam20ps05/yt-dlp.git", branch = "instagram_fix" }
##youtube_dl = { git = "https://github.com/l1ving/youtube-dl.git" }
##youtube_dl = { git = "https://github.com/gilou/youtube-dl.git", branch = "bandcamp_update" }
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ restructuredtext-lint==1.4.0 ; python_version >= "3.9" and python_version < "4.0
ruamel-yaml-clib==0.2.7 ; platform_python_implementation == "CPython" and python_version < "3.11" and python_version >= "3.9"
ruamel-yaml==0.17.21 ; python_version >= "3.9" and python_version < "4.0"
safety==2.3.4 ; python_version >= "3.9" and python_version < "4.0"
setuptools==67.3.2 ; python_version >= "3.9" and python_version < "4.0"
setuptools==67.3.3 ; python_version >= "3.9" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
smmap==5.0.0 ; python_version >= "3.9" and python_version < "4.0"
snowballstemmer==2.2.0 ; python_version >= "3.9" and python_version < "4.0"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ requests[socks]==2.28.2 ; python_version >= "3.9" and python_version < "4"
rfc3986[idna2008]==1.5.0 ; python_version >= "3.9" and python_version < "4.0"
scdl==2.7.3 ; python_version >= "3.9" and python_version < "4.0"
sdnotify==0.3.2 ; python_version >= "3.9" and python_version < "4.0"
setuptools==67.3.2 ; python_version >= "3.9" and python_version < "4.0"
setuptools==67.3.3 ; python_version >= "3.9" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
sniffio==1.3.0 ; python_version >= "3.9" and python_version < "4.0"
soundcloud-v2==1.3.1 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -57,5 +57,5 @@ unicode-slugify==0.1.5 ; python_version >= "3.9" and python_version < "4.0"
unidecode==1.3.6 ; python_version >= "3.9" and python_version < "4.0"
urllib3==1.26.14 ; python_version >= "3.9" and python_version < "4"
websockets==10.4 ; python_version >= "3.9" and python_version < "4.0"
yt-dlp==2023.2.17 ; python_version >= "3.9" and python_version < "4.0"
yt-dlp @ git+https://github.com/yt-dlp/yt-dlp.git@master ; python_version >= "3.9" and python_version < "4.0"
zipp==3.14.0 ; python_version >= "3.9" and python_version < "3.10"
2 changes: 2 additions & 0 deletions scdlbot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO maybe move some importable code here
# https://stackoverflow.com/a/70027834/2490759
4 changes: 3 additions & 1 deletion scdlbot/scdlbot.py → scdlbot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import asyncio
import concurrent.futures
import datetime
Expand Down Expand Up @@ -1295,7 +1297,7 @@ async def callback_monitor(context: ContextTypes.DEFAULT_TYPE):

def main():
# Start exposing Prometheus/OpenMetrics metrics:
prometheus_client.start_http_server(METRICS_PORT, addr=METRICS_HOST, registry=REGISTRY)
prometheus_client.start_http_server(addr=METRICS_HOST, port=METRICS_PORT, registry=REGISTRY)

# Maybe we can use token again if we will buy SoundCloud Go+
# https://github.com/flyingrub/scdl/issues/429
Expand Down

0 comments on commit 036cac1

Please sign in to comment.