Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Margarita-pyth committed Mar 25, 2022
0 parents commit 82d4898
Show file tree
Hide file tree
Showing 11 changed files with 973 additions and 0 deletions.
152 changes: 152 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Папки, создаваемые средой разработки
.idea
.DS_Store
.AppleDouble
.LSOverride

*.sublime-project
*.sublime-workspace

.vscode/
*.code-workspace

# Local History for Visual Studio Code
.history/

.mypy_cache

# папки со статикой и медиа
static/
posts/static/
media/

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python homework.py
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# homework_bot
python telegram bot
83 changes: 83 additions & 0 deletions homework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
...

load_dotenv()


PRACTICUM_TOKEN = ...
TELEGRAM_TOKEN = ...
TELEGRAM_CHAT_ID = ...

RETRY_TIME = 600
ENDPOINT = 'https://practicum.yandex.ru/api/user_api/homework_statuses/'
HEADERS = {'Authorization': f'OAuth {PRACTICUM_TOKEN}'}


HOMEWORK_STATUSES = {
'approved': 'Работа проверена: ревьюеру всё понравилось. Ура!',
'reviewing': 'Работа взята на проверку ревьюером.',
'rejected': 'Работа проверена: у ревьюера есть замечания.'
}


def send_message(bot, message):
...


def get_api_answer(current_timestamp):
timestamp = current_timestamp or int(time.time())
params = {'from_date': timestamp}

...


def check_response(response):

...


def parse_status(homework):
homework_name = ...
homework_status = ...

...

verdict = ...

...

return f'Изменился статус проверки работы "{homework_name}". {verdict}'


def check_tokens():
...


def main():
"""Основная логика работы бота."""

...

bot = telegram.Bot(token=TELEGRAM_TOKEN)
current_timestamp = int(time.time())

...

while True:
try:
response = ...

...

current_timestamp = ...
time.sleep(RETRY_TIME)

except Exception as error:
message = f'Сбой в работе программы: {error}'
...
time.sleep(RETRY_TIME)
else:
...


if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
norecursedirs = env/*
addopts = -vv -p no:cacheprovider -p no:warnings
testpaths = tests/
python_files = test_*.py
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
flake8==3.9.2
flake8-docstrings==1.6.0
pytest==6.2.5
python-dotenv==0.19.0
python-telegram-bot==13.7
requests==2.26.0
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
ignore =
W503,
D100,
D205,
D401
filename =
./homework.py
exclude =
tests/,
venv/,
env/
max-complexity = 10
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from os.path import abspath, dirname

root_dir = dirname(dirname(abspath(__file__)))
sys.path.append(root_dir)

pytest_plugins = [
'tests.fixtures.fixture_data'
]
21 changes: 21 additions & 0 deletions tests/fixtures/fixture_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random
from datetime import datetime

import pytest


@pytest.fixture
def random_timestamp():
left_ts = 1000198000
right_ts = 1000198991
return random.randint(left_ts, right_ts)


@pytest.fixture
def current_timestamp():
return datetime.now().timestamp()


@pytest.fixture
def api_url():
return 'https://practicum.yandex.ru/api/user_api/homework_statuses/'
Loading

0 comments on commit 82d4898

Please sign in to comment.