Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eaf4846
Fix type error in at comparion date
deymonster Jan 12, 2024
3f84f16
Add shortages report, file report in memory
deymonster Jan 28, 2024
9d6a606
Fix codestyle a little
deymonster Jan 28, 2024
76682ba
Remove some files
deymonster Jan 28, 2024
e4bd406
Remove test
deymonster Jan 28, 2024
b72d395
Add all info about each shortage
deymonster Jan 30, 2024
94ccce4
Add pass Office with None data
deymonster Feb 15, 2024
f2fdb8e
Add postgresql service to save data to DB
deymonster Feb 20, 2024
fe10e26
Add star.sh with alembic upgrade
deymonster Feb 20, 2024
189a0b9
Convert return_sum to int
deymonster Feb 20, 2024
4a728ad
Change office_rating and percent to float, add round in service
deymonster Feb 21, 2024
3d53763
Add office model with init data, update sale model
deymonster Feb 28, 2024
084e931
Update calculating fields of saleobject model
deymonster Feb 28, 2024
1c2c4a4
Add new data field to DB - office_speed_sum
deymonster Feb 29, 2024
f737836
Added checking office_speed_sum
deymonster Feb 29, 2024
16cda2a
Update profitability, add office_speed_sum to report csv
deymonster Mar 2, 2024
9267e66
Add logging for office data and skip if none
deymonster Mar 4, 2024
82d8d72
Add offices commands to work with them
deymonster Mar 21, 2024
c7cbb94
Change API bot
deymonster Mar 21, 2024
eff8510
Bugfix with update fields
deymonster Mar 22, 2024
769466a
Add new report Officerates and new Table in DB
deymonster Jun 26, 2024
0fd99ec
New order in officeratingobject
deymonster Jun 26, 2024
07922fd
Change token
deymonster Jun 26, 2024
70d2220
Update logic while adding new OfficeRatingObject
deymonster Jun 26, 2024
b1f45ac
Fix dump offices to csv
deymonster Jun 27, 2024
2f3b1b2
Fix token
deymonster Jun 27, 2024
a41dd3e
Fix empty office_id and name in Shortages
deymonster Jun 29, 2024
f07c480
Add rate by region
deymonster Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test and Build

on:
push:
branches:
- main

jobs:
# run_test:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Set up Python
# uses: actions/setup-python@v2
# with:
# python-version: 3.11
#
# - name: Install pycodestyle
# run: |
# python -m pip install --upgrade pip
# pip install pycodestyle
#
# - name: Check codestyle
# run: pycodestyle ./src/*.py


deploy_to_server:
# needs: [run_test]
runs-on: ubuntu-latest
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }}
steps:
- uses: D3rHase/ssh-command-action@v0.2.2
with:
host: ${{ secrets.SERVER_HOST }}
user: ${{ secrets.SERVER_USERNAME }}
private_key: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
cd wb_parser_bot;
docker rm wb-parser-bot;
make stop;
git pull origin main;
make build;
make run;


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
__pycache__/
*.DS_Store
.idea/

.src/main.py
.src/test_parser.py
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ RUN useradd -m -d /home/${USER} ${USER} \

RUN mkdir -p ${PROJECTPATH}

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait ${PROJECTPATH}/wait
RUN chmod +x ${PROJECTPATH}/wait

RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 - \
&& cd /usr/local/bin \
&& ln -s /etc/poetry/bin/poetry \
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ help:
make -pRrq -f $(THIS_FILE) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'

build:
docker-compose -f docker-compose.yaml build $(c)
docker compose -f docker-compose.yaml build $(c)
run:
docker-compose -f docker-compose.yaml up -d $(c)
docker compose -f docker-compose.yaml up -d $(c)
stop:
docker-compose -f docker-compose.yaml stop $(c)
docker compose -f docker-compose.yaml stop $(c)
restart:
docker-compose -f docker-compose.yaml stop $(c)
docker-compose -f docker-compose.yaml up -d $(c)
docker compose -f docker-compose.yaml stop $(c)
docker compose -f docker-compose.yaml up -d $(c)
destroy:
docker-compose -f docker-compose.yaml down -v $(c)
docker compose -f docker-compose.yaml down -v $(c)
log:
docker-compose -f docker-compose.yaml logs --tail=150 -f wb-parser-bot
docker compose -f docker-compose.yaml logs --tail=150 -f wb-parser-bot
shell:
docker-compose -f docker-compose.yaml exec wb-parser-bot /bin/bash
docker compose -f docker-compose.yaml exec wb-parser-bot /bin/bash



23 changes: 22 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
version: '3.8'

services:
wb-db:
image: postgres:14-alpine
container_name: wb-db
restart: always
ports:
- "5432:5432"
volumes:
- wb-db-data:/var/lib/postgresql/data/pgdata
env_file:
- .env
environment:
PGDATA: /var/lib/postgresql/data/pgdata
wb-parser-bot:
build:
context: .
dockerfile: Dockerfile
container_name: wb-parser-bot
image: wb-parser-bot:latest
command: ["python3", "main_bot.py"]
command: bash start.sh
env_file:
- .env
environment:
WAIT-HOSTS: "wb-db"
volumes:
- ./src:/home/wb_user/bot
restart: on-failure
depends_on:
- wb-db

volumes:
wb-db-data:




1,049 changes: 665 additions & 384 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ python-dotenv = "^1.0.0"
numpy = "^1.23.2"
pandas = "^2.1.0"
schedule = "^1.2.0"
python-telegram-bot = "^20.5"
python-telegram-bot = "^21.0"
sqlalchemy = "^2.0.21"
psycopg2-binary = "^2.9.8"
pydantic = "^2.6.1"
alembic = "^1.13.1"


[build-system]
Expand Down
117 changes: 117 additions & 0 deletions src/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = alembic

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8


sqlalchemy.url = postgresql://%(DB_USER)s:%(DB_PASSWORD)s@%(DB_HOST)s:%(DB_PORT)s/%(DB_NAME)s


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
1 change: 1 addition & 0 deletions src/alembic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
90 changes: 90 additions & 0 deletions src/alembic/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context
from db.base_class import Base

from utils.env import POSTGRES_SERVER, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, POSTGRES_PORT
from parser.models import SaleObject


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

section = config.config_ini_section
config.set_section_option(section, "DB_HOST", str(POSTGRES_SERVER))
config.set_section_option(section, "DB_USER", str(POSTGRES_USER))
config.set_section_option(section, "DB_PASSWORD", str(POSTGRES_PASSWORD))
config.set_section_option(section, "DB_NAME", str(POSTGRES_DB))
config.set_section_option(section, "DB_PORT", str(POSTGRES_PORT))

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online() -> None:
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
26 changes: 26 additions & 0 deletions src/alembic/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}


def upgrade() -> None:
${upgrades if upgrades else "pass"}


def downgrade() -> None:
${downgrades if downgrades else "pass"}
Loading