-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelp_form.py
More file actions
154 lines (137 loc) · 5.67 KB
/
help_form.py
File metadata and controls
154 lines (137 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import sys
import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from os.path import basename
from secondary_functions import Language
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QTextEdit, QPushButton, QMessageBox
'''Появляется окно, в котором можно написать сообщение.
В итоге мы получим вопрос от пользователя на нашу почту,
А сам пользователь получит информационное письмо, что ответ поступит скоро'''
LANGUAGE = Language().request
class Main(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle(LANGUAGE("support"))
self.setGeometry(600, 300, 500, 570)
self.initUi()
def initUi(self):
self.setStyleSheet("QWidget{background-color: #ffa500;}")
self.email = QLineEdit(self)
self.email.setFont(QFont("Times New Roman", 14))
self.email.setPlaceholderText(LANGUAGE("in_em"))
self.email.setFixedHeight(40)
self.email.setStyleSheet("""
QLineEdit{
border: 1px solid #CCD6DD;
background-color: #fff;
border-radius: 15px;
}
""")
self.email.resize(440, 20)
self.email.move(30, 20)
self.question = QTextEdit(self)
self.question.setFont(QFont("Times New Roman", 14))
self.question.setPlaceholderText(LANGUAGE("problem"))
self.question.setStyleSheet("""
QTextEdit{
border: 1px solid #CCD6DD;
background-color: #fff;
border-radius: 15px;
}""")
self.question.resize(440, 440)
self.question.move(30, 70)
self.send_question = QPushButton(self)
self.send_question.setFont(QFont("Times New Roman", 14))
self.send_question.setText(LANGUAGE("send"))
self.send_question.move(350, 520)
self.send_question.clicked.connect(self.sending)
self.send_question.setStyleSheet("""
QPushButton:hover {
background-color: #AAB6FB;
border-style: outset;
border-width: 2px;
border-radius: 15px;
border-color: black;
padding: 4px;
}
QPushButton:!hover {
background-color: #fff;
border-style: outset;
border-width: 2px;
border-radius: 15px;
border-color: black;
padding: 4px;}
QPushButton:pressed {
background-color: rgb(0, 255, 0);
}""")
def sending(self):
if self.email.text() == '':
msg = QMessageBox(self)
msg.setText(LANGUAGE("wrong3"))
msg.setIcon(QMessageBox.Critical)
msg.setWindowTitle(LANGUAGE("mistake"))
msg.setFont(QFont("Times New Roman", 14))
x = msg.exec_()
elif self.question.toPlainText() == '':
msg = QMessageBox(self)
msg.setIcon(QMessageBox.Critical)
msg.setText(LANGUAGE("wrong2"))
msg.setWindowTitle(LANGUAGE("mistake"))
msg.setFont(QFont("Times New Roman", 14))
x = msg.exec_()
else:
try:
addr_from = 'help.converter@yandex.ru'
password = 'YandexLyceum2021'
server = smtplib.SMTP('smtp.yandex.ru', 587)
server.ehlo()
server.starttls()
server.login(addr_from, password)
addr_to = self.email.text()
msg = MIMEMultipart()
msg['From'] = addr_from
msg['To'] = addr_to
msg['Subject'] = 'Подтверждение'
body = 'Здравствуйте! \n' \
'Мы получили Ваше сообщение и ответим в течение 3-х рабочих дней.\n\n' \
'С уважением, команда разработчиков.'
msg.attach(MIMEText(body, 'plain'))
server.send_message(msg)
msg = MIMEMultipart()
msg['From'] = addr_from
msg['To'] = addr_from
msg['Subject'] = 'Новый вопрос'
body = f'Получен новый вопрос.\nОтправитель: {addr_to}\n' \
f'Текст: "{self.question.toPlainText()}"'
msg.attach(MIMEText(body, 'plain'))
path_report = 'reports/report.json'
with open(path_report, 'rb') as report:
part = MIMEApplication(
report.read(),
name=basename(path_report)
)
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(path_report)
msg.attach(part)
server.send_message(msg)
server.quit()
msg = QMessageBox(self)
msg.setText(LANGUAGE("send_request"))
msg.setWindowTitle(LANGUAGE("title_success"))
msg.setFont(QFont("Times New Roman", 14))
x = msg.exec_()
self.close()
except Exception as e:
msg = QMessageBox(self)
msg.setText(LANGUAGE("wrong1"))
msg.setIcon(QMessageBox.Critical)
msg.setWindowTitle(LANGUAGE("mistake"))
msg.setFont(QFont("Times New Roman", 14))
x = msg.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
main = Main()
main.show()
app.exit(app.exec_())