Skip to content

Commit 3352afe

Browse files
committed
Initial commit
0 parents  commit 3352afe

File tree

11 files changed

+973
-0
lines changed

11 files changed

+973
-0
lines changed

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# Папки, создаваемые средой разработки
132+
.idea
133+
.DS_Store
134+
.AppleDouble
135+
.LSOverride
136+
137+
*.sublime-project
138+
*.sublime-workspace
139+
140+
.vscode/
141+
*.code-workspace
142+
143+
# Local History for Visual Studio Code
144+
.history/
145+
146+
.mypy_cache
147+
148+
# папки со статикой и медиа
149+
static/
150+
posts/static/
151+
media/
152+

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: python homework.py

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# homework_bot
2+
python telegram bot

homework.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
...
2+
3+
load_dotenv()
4+
5+
6+
PRACTICUM_TOKEN = ...
7+
TELEGRAM_TOKEN = ...
8+
TELEGRAM_CHAT_ID = ...
9+
10+
RETRY_TIME = 600
11+
ENDPOINT = 'https://practicum.yandex.ru/api/user_api/homework_statuses/'
12+
HEADERS = {'Authorization': f'OAuth {PRACTICUM_TOKEN}'}
13+
14+
15+
HOMEWORK_STATUSES = {
16+
'approved': 'Работа проверена: ревьюеру всё понравилось. Ура!',
17+
'reviewing': 'Работа взята на проверку ревьюером.',
18+
'rejected': 'Работа проверена: у ревьюера есть замечания.'
19+
}
20+
21+
22+
def send_message(bot, message):
23+
...
24+
25+
26+
def get_api_answer(current_timestamp):
27+
timestamp = current_timestamp or int(time.time())
28+
params = {'from_date': timestamp}
29+
30+
...
31+
32+
33+
def check_response(response):
34+
35+
...
36+
37+
38+
def parse_status(homework):
39+
homework_name = ...
40+
homework_status = ...
41+
42+
...
43+
44+
verdict = ...
45+
46+
...
47+
48+
return f'Изменился статус проверки работы "{homework_name}". {verdict}'
49+
50+
51+
def check_tokens():
52+
...
53+
54+
55+
def main():
56+
"""Основная логика работы бота."""
57+
58+
...
59+
60+
bot = telegram.Bot(token=TELEGRAM_TOKEN)
61+
current_timestamp = int(time.time())
62+
63+
...
64+
65+
while True:
66+
try:
67+
response = ...
68+
69+
...
70+
71+
current_timestamp = ...
72+
time.sleep(RETRY_TIME)
73+
74+
except Exception as error:
75+
message = f'Сбой в работе программы: {error}'
76+
...
77+
time.sleep(RETRY_TIME)
78+
else:
79+
...
80+
81+
82+
if __name__ == '__main__':
83+
main()

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
norecursedirs = env/*
3+
addopts = -vv -p no:cacheprovider -p no:warnings
4+
testpaths = tests/
5+
python_files = test_*.py

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flake8==3.9.2
2+
flake8-docstrings==1.6.0
3+
pytest==6.2.5
4+
python-dotenv==0.19.0
5+
python-telegram-bot==13.7
6+
requests==2.26.0

setup.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
ignore =
3+
W503,
4+
D100,
5+
D205,
6+
D401
7+
filename =
8+
./homework.py
9+
exclude =
10+
tests/,
11+
venv/,
12+
env/
13+
max-complexity = 10

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
from os.path import abspath, dirname
3+
4+
root_dir = dirname(dirname(abspath(__file__)))
5+
sys.path.append(root_dir)
6+
7+
pytest_plugins = [
8+
'tests.fixtures.fixture_data'
9+
]

tests/fixtures/fixture_data.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
from datetime import datetime
3+
4+
import pytest
5+
6+
7+
@pytest.fixture
8+
def random_timestamp():
9+
left_ts = 1000198000
10+
right_ts = 1000198991
11+
return random.randint(left_ts, right_ts)
12+
13+
14+
@pytest.fixture
15+
def current_timestamp():
16+
return datetime.now().timestamp()
17+
18+
19+
@pytest.fixture
20+
def api_url():
21+
return 'https://practicum.yandex.ru/api/user_api/homework_statuses/'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy