Skip to content

Commit 60eacc9

Browse files
fix: send email
1 parent 99699e6 commit 60eacc9

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
lines changed

generate_word/generate_file.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os.path import join
1+
from os.path import join, exists
22
from settings import get_settings
33
from docxtpl import DocxTemplate
44
from datetime import date, timedelta
@@ -16,5 +16,6 @@ def create_report(counter: int, avg_load: float, max_load: float, site_name: str
1616
}
1717
)
1818
current_date = (date.today() - timedelta(days=1)).strftime('%d-%m-%Y')
19-
template_word.save(join(get_settings().static_dir, f'{current_date}-{site_name}.docx'))
20-
return join(get_settings().static_dir, f'{current_date}-{site_name}.docx')
19+
path_report = join(get_settings().static_dir, f'{current_date}-{site_name}.docx')
20+
template_word.save(path_report)
21+
return path_report

main.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ async def redirect_page_docs():
4949

5050
@app.post('/traffic/',
5151
response_model=Traffic)
52-
async def calculate(identification: str,
53-
session: AsyncSession = Depends(get_session)):
52+
async def calculate(
53+
identification: str,
54+
session: AsyncSession = Depends(get_session)):
5455
site = (await session.execute(select(Site).where(Site.identification == identification))).first()
5556
if site is None:
5657
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail='Запрашиваемый ключ доступа не найден')
@@ -90,10 +91,11 @@ async def form_send(request: Request):
9091

9192
@app.post('/identification/',
9293
response_model=Site)
93-
async def generate_secret_key(website_url: str = Form(...),
94-
secret_key: str = Form(...),
95-
list_email: str = Form(...),
96-
session: AsyncSession = Depends(get_session)):
94+
async def generate_secret_key(
95+
website_url: str = Form(...),
96+
secret_key: str = Form(...),
97+
list_email: str = Form(...),
98+
session: AsyncSession = Depends(get_session)):
9799
verify_site = (await session.execute(select(Site).where(Site.site_name == website_url))).first()
98100
if verify_site is None:
99101
email_id = (await session.execute(insert(Email).values(name=list_email))).inserted_primary_key[0]
@@ -111,9 +113,10 @@ async def generate_secret_key(website_url: str = Form(...),
111113
@app.get('/info/{identification_site}',
112114
response_model=Traffic,
113115
response_class=HTMLResponse)
114-
async def infi_traffic(identification_site: str,
115-
request: Request,
116-
session: AsyncSession = Depends(get_session)):
116+
async def infi_traffic(
117+
identification_site: str,
118+
request: Request,
119+
session: AsyncSession = Depends(get_session)):
117120
site = (await session.execute(select(Site).where(Site.identification == identification_site))).first()
118121
if site is None:
119122
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail='Запрашиваемый ключ доступа не найден')

send_message/send_email.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
from email.mime.application import MIMEApplication
66

77

8-
async def send_file(login: str, password: str, sender: str, receivers: str,
9-
attachment_path: str, smtp_server: str, port: int, site_name: str):
8+
async def send_file(
9+
login: str,
10+
password: str,
11+
sender: str,
12+
receivers: str,
13+
attachment_path: str,
14+
smtp_server: str,
15+
port: int,
16+
site_name: str):
1017
current_date = (date.today() - timedelta(days=1)).strftime('%d-%m-%Y')
1118
message = MIMEMultipart()
1219
message['Subject'] = 'Отчет о состоянии IT-инфраструктуры и результатах ' \
@@ -26,4 +33,3 @@ async def send_file(login: str, password: str, sender: str, receivers: str,
2633
with smtplib.SMTP_SSL(smtp_server, port) as server:
2734
server.login(login, password)
2835
server.sendmail(sender, receivers.split(', '), message.as_string())
29-
server.quit()

static/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Директория для статических файлов

task.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ async def send_message():
3939
sleep(1)
4040

4141

42-
schedule.every().day.at(f'{NOTIFICATION_SEND_TIME}').do(send_message)
43-
#schedule.every(20).seconds.do(send_message)
42+
# schedule.every().day.at(f'{NOTIFICATION_SEND_TIME}').do(send_message)
43+
schedule.every(20).seconds.do(send_message)
4444

4545
while True:
4646
get_event_loop().run_until_complete(schedule.run_pending())

templates/post_identification.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
<div align="center" class="container">
1010
<form action="/identification/" enctype="multipart/form-data" method="post">
1111
<div class="field">
12-
1312
<div class="control">
1413
<label for="website_url" class="label">Введите URL сайта</label>
15-
<input id="website_url" class="input" placeholder="URL site" size="100" name="website_url">
14+
<input id="website_url" class="input" placeholder="https://example.com" size="100" name="website_url">
1615
</div>
1716
</div>
1817
<div class="field">
1918
<div class="control">
20-
<label for="list_email" class="label">Введите email(s) (через запятую) на который будут приходить отчеты</label>
19+
<label for="list_email" class="label">Введите email(s) (через запятую с пробелом ", ") на который будут приходить отчеты</label>
2120
<input id="list_email" class="input" placeholder="[email protected], [email protected]" size="100" name="list_email" type="email">
2221
</div>
2322
</div>

templates/statistics.html

+18-18
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
</head>
88
<body>
99
<div style="display: flex; justify-content: center">
10-
<table class="table">
11-
<thead>
12-
<tr>
13-
<th>Current date</th>
14-
<th>Counter request</th>
15-
<th>Maximum load</th>
16-
<th>Average load</th>
17-
</tr>
18-
</thead>
19-
<tbody>
20-
<tr>
21-
<td>{{ create_at }}</td>
22-
<td>{{ counter }}</td>
23-
<td>{{ maximum_load }}</td>
24-
<td>{{ average_load }}</td>
25-
</tr>
26-
</tbody>
27-
</table>
10+
<table class="table">
11+
<thead>
12+
<tr>
13+
<th>Current date</th>
14+
<th>Counter request</th>
15+
<th>Maximum load</th>
16+
<th>Average load</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td>{{ create_at }}</td>
22+
<td>{{ counter }}</td>
23+
<td>{{ maximum_load }}</td>
24+
<td>{{ average_load }}</td>
25+
</tr>
26+
</tbody>
27+
</table>
2828
</div>
2929

3030
</body>

0 commit comments

Comments
 (0)