-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 82d4898
Showing
11 changed files
with
973 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
worker: python homework.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# homework_bot | ||
python telegram bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/' |
Oops, something went wrong.