add save/load and view response

This commit is contained in:
FullGreaM 2022-05-22 15:37:32 +03:00
parent 3785698e2c
commit dbd661776e
6 changed files with 581 additions and 339 deletions

Binary file not shown.

Binary file not shown.

111
app.py
View File

@ -9,6 +9,12 @@ import json, requests, os, random, pyperclip, traceback, vk_api
history_requests = list()
request_status = list()
history_responses = list()
try:
os.mkdir('saves');
except Exception as exc:
pass
def genToken(lenght=32, dictonary='0123456789abcdef'):
@ -43,7 +49,12 @@ class callback_server(Thread):
}
request_status.append(0)
history_requests.append(r_body)
history_responses.append('<p>Ждём ответа от сервера...</p>')
r = requests.post(server_url, json=r_body)
try:
history_responses[history_requests.index(r_body)] = r.text
except:
history_responses[history_requests.index(r_body)] = f"<p>Ошибка сервера: {r.statusCode}</p>"
if r.text != ret_str:
request_status[history_requests.index(r_body)] = -1
exc = callback_clientException('Invalid response code')
@ -83,8 +94,14 @@ class callback_server(Thread):
}
request_status.append(0)
history_requests.append(r_body)
history_responses.append('<p>Ждём ответа от сервера...</p>')
try:
r = requests.post(self.server_url, json=r_body)
try:
history_responses[history_requests.index(r_body)] = r.text
except:
history_responses[history_requests.index(r_body)] = f"<p>Ошибка сервера: {r.statusCode}</p>"
if r.text != 'ok':
request_status[history_requests.index(r_body)] = -1
else:
@ -114,6 +131,18 @@ class app_win(QMainWindow):
self.setMouseTracking(True)
self.callback_server = callback_server()
self.saves = list()
for root, dirs, files in os.walk('saves'):
for _dir in dirs:
files_in_dir = list()
for _root, _dirs, _files in os.walk(f"saves/{_dir}"):
for file in _files:
files_in_dir.append(file)
if ('group_id.txt' in files_in_dir) and ('ret_str.txt' in files_in_dir) and ('secret_key.txt' in files_in_dir) and ('server_url.txt' in files_in_dir) and ('token.txt' in files_in_dir):
self.saves.append(_dir)
self.ui.saveList.addItem(_dir)
# Other
retStr_file = open('ret_str.txt', 'r', encoding='utf-8')
self.ret_str = retStr_file.read()
@ -154,6 +183,85 @@ class app_win(QMainWindow):
self.ui.copy_ret_str.clicked.connect(lambda: pyperclip.copy(self.ret_str))
self.ui.gen_ret_str.clicked.connect(self.generate_returnString)
self.ui.start.clicked.connect(self.connect_callback)
self.ui.new_saveButton.clicked.connect(self.new_saveSession)
self.ui.loadButton.clicked.connect(self.loadSession)
self.ui.saveButton.clicked.connect(self.saveSession)
def loadSession(self):
text = self.ui.saveList.currentText()
with open('group_id.txt', 'wb') as f:
with open(f"saves/{text}/group_id.txt", 'rb') as fs:
content = fs.read()
f.write(content)
self.ui.group_idInput.setText(content.decode("utf-8"))
with open('ret_str.txt', 'wb') as f:
with open(f"saves/{text}/ret_str.txt", 'rb') as fs:
content = fs.read()
f.write(content)
self.ui.ret_str.setText(f"Строка, которую должен вернуть сервер: {content.decode('utf-8')}")
with open('secret_key.txt', 'wb') as f:
with open(f"saves/{text}/secret_key.txt", 'rb') as fs:
content = fs.read()
f.write(content)
self.ui.secret_key.setText(content.decode('utf-8'))
with open('server_url.txt', 'wb') as f:
with open(f"saves/{text}/server_url.txt", 'rb') as fs:
content = fs.read()
f.write(content)
self.ui.server_url.setText(content.decode('utf-8'))
with open('token.txt', 'wb') as f:
with open(f"saves/{text}/token.txt", 'rb') as fs:
content = fs.read()
f.write(content)
self.ui.group_token.setText(content.decode('utf-8'))
def saveSession(self):
text = self.ui.saveList.currentText()
if True:
try:
with open('group_id.txt', 'rb') as f:
with open(f"saves/{text}/group_id.txt", 'wb') as fs:
fs.write(f.read())
with open('ret_str.txt', 'rb') as f:
with open(f"saves/{text}/ret_str.txt", 'wb') as fs:
fs.write(f.read())
with open('secret_key.txt', 'rb') as f:
with open(f"saves/{text}/secret_key.txt", 'wb') as fs:
fs.write(f.read())
with open('server_url.txt', 'rb') as f:
with open(f"saves/{text}/server_url.txt", 'wb') as fs:
fs.write(f.read())
with open('token.txt', 'rb') as f:
with open(f"saves/{text}/token.txt", 'wb') as fs:
fs.write(f.read())
except Exception as exc:
pass
def new_saveSession(self):
text, ok = QInputDialog.getText(self, 'Сохранить сессию', 'Введите имя сессии:')
if ok and not(text in self.saves):
try:
os.mkdir(f"saves/{text}")
with open('group_id.txt', 'rb') as f:
with open(f"saves/{text}/group_id.txt", 'wb') as fs:
fs.write(f.read())
with open('ret_str.txt', 'rb') as f:
with open(f"saves/{text}/ret_str.txt", 'wb') as fs:
fs.write(f.read())
with open('secret_key.txt', 'rb') as f:
with open(f"saves/{text}/secret_key.txt", 'wb') as fs:
fs.write(f.read())
with open('server_url.txt', 'rb') as f:
with open(f"saves/{text}/server_url.txt", 'wb') as fs:
fs.write(f.read())
with open('token.txt', 'rb') as f:
with open(f"saves/{text}/token.txt", 'wb') as fs:
fs.write(f.read())
self.saves.append(text)
self.ui.saveList.addItem(text)
except Exception as exc:
pass
def update_info_requests(self):
global history_requests, request_status
@ -173,6 +281,8 @@ class app_win(QMainWindow):
def qTimer_void(self):
global history_requests, request_status
self.ui.loadButton.setEnabled(len(self.saves) > 0)
self.ui.saveButton.setEnabled(len(self.saves) > 0)
self.ui.start.setEnabled(bool(self.ui.server_url.text()) and bool(self.ui.group_idInput.text()) and bool(self.ui.group_token.text()) and not(self.connected))
if self.parsed_requests != history_requests or self.parsed_responses != request_status:
self.update_info_requests()
@ -184,6 +294,7 @@ class app_win(QMainWindow):
if self.json_code_view != JSON_CONTENT:
self.json_code_view = JSON_CONTENT
self.ui.requestBody.setText(self.json_code_view)
self.ui.responseBody.setText(history_responses[self.ui.requestsWidget.currentRow()])
if self.ui.group_idInput.text() != filtrating_integer(self.ui.group_idInput.text()):
self.ui.group_idInput.setText(filtrating_integer(self.ui.group_idInput.text()))

107
main.ui
View File

@ -82,7 +82,7 @@
<x>290</x>
<y>30</y>
<width>301</width>
<height>41</height>
<height>21</height>
</rect>
</property>
<property name="text">
@ -92,8 +92,8 @@
<widget class="QPushButton" name="copy_ret_str">
<property name="geometry">
<rect>
<x>504</x>
<y>80</y>
<x>500</x>
<y>60</y>
<width>91</width>
<height>23</height>
</rect>
@ -109,7 +109,7 @@
<property name="geometry">
<rect>
<x>410</x>
<y>80</y>
<y>60</y>
<width>91</width>
<height>23</height>
</rect>
@ -150,6 +150,70 @@
<string>id группы</string>
</property>
</widget>
<widget class="QComboBox" name="saveList">
<property name="geometry">
<rect>
<x>290</x>
<y>120</y>
<width>131</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="loadButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>520</x>
<y>120</y>
<width>71</width>
<height>23</height>
</rect>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Загрузить</string>
</property>
</widget>
<widget class="QPushButton" name="new_saveButton">
<property name="geometry">
<rect>
<x>420</x>
<y>120</y>
<width>101</width>
<height>23</height>
</rect>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Сохранить как</string>
</property>
</widget>
<widget class="QPushButton" name="saveButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>520</x>
<y>100</y>
<width>71</width>
<height>23</height>
</rect>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Сохранить</string>
</property>
</widget>
</widget>
<widget class="QPushButton" name="start">
<property name="geometry">
@ -196,7 +260,7 @@
<x>320</x>
<y>180</y>
<width>291</width>
<height>331</height>
<height>191</height>
</rect>
</property>
<property name="cursor" stdset="0">
@ -236,6 +300,39 @@ p, li { white-space: pre-wrap; }
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/response_codes/Sending.png&quot;/&gt; Сервер не запущен&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>320</x>
<y>370</y>
<width>291</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Ответ&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QTextBrowser" name="responseBody">
<property name="geometry">
<rect>
<x>320</x>
<y>390</y>
<width>291</width>
<height>121</height>
</rect>
</property>
<property name="cursor" stdset="0">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
<resources>
<include location="source.qrc"/>

View File

@ -30,14 +30,14 @@ class Ui_Form(object):
self.secret_key.setGeometry(QtCore.QRect(20, 70, 261, 20))
self.secret_key.setObjectName("secret_key")
self.ret_str = QtWidgets.QLabel(self.groupBox)
self.ret_str.setGeometry(QtCore.QRect(290, 30, 301, 41))
self.ret_str.setGeometry(QtCore.QRect(290, 30, 301, 21))
self.ret_str.setObjectName("ret_str")
self.copy_ret_str = QtWidgets.QPushButton(self.groupBox)
self.copy_ret_str.setGeometry(QtCore.QRect(504, 80, 91, 23))
self.copy_ret_str.setGeometry(QtCore.QRect(500, 60, 91, 23))
self.copy_ret_str.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.copy_ret_str.setObjectName("copy_ret_str")
self.gen_ret_str = QtWidgets.QPushButton(self.groupBox)
self.gen_ret_str.setGeometry(QtCore.QRect(410, 80, 91, 23))
self.gen_ret_str.setGeometry(QtCore.QRect(410, 60, 91, 23))
self.gen_ret_str.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.gen_ret_str.setObjectName("gen_ret_str")
self.group_token = QtWidgets.QLineEdit(self.groupBox)
@ -47,6 +47,23 @@ class Ui_Form(object):
self.group_idInput = QtWidgets.QLineEdit(self.groupBox)
self.group_idInput.setGeometry(QtCore.QRect(20, 100, 261, 20))
self.group_idInput.setObjectName("group_idInput")
self.saveList = QtWidgets.QComboBox(self.groupBox)
self.saveList.setGeometry(QtCore.QRect(290, 120, 131, 22))
self.saveList.setObjectName("saveList")
self.loadButton = QtWidgets.QPushButton(self.groupBox)
self.loadButton.setEnabled(False)
self.loadButton.setGeometry(QtCore.QRect(520, 120, 71, 23))
self.loadButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.loadButton.setObjectName("loadButton")
self.new_saveButton = QtWidgets.QPushButton(self.groupBox)
self.new_saveButton.setGeometry(QtCore.QRect(420, 120, 101, 23))
self.new_saveButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.new_saveButton.setObjectName("new_saveButton")
self.saveButton = QtWidgets.QPushButton(self.groupBox)
self.saveButton.setEnabled(False)
self.saveButton.setGeometry(QtCore.QRect(520, 100, 71, 23))
self.saveButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.saveButton.setObjectName("saveButton")
self.start = QtWidgets.QPushButton(Form)
self.start.setGeometry(QtCore.QRect(530, 520, 75, 23))
self.start.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
@ -58,7 +75,7 @@ class Ui_Form(object):
self.requestsWidget.setGeometry(QtCore.QRect(10, 180, 311, 331))
self.requestsWidget.setObjectName("requestsWidget")
self.requestBody = QtWidgets.QTextBrowser(Form)
self.requestBody.setGeometry(QtCore.QRect(320, 180, 291, 331))
self.requestBody.setGeometry(QtCore.QRect(320, 180, 291, 191))
self.requestBody.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.requestBody.setObjectName("requestBody")
self.label_3 = QtWidgets.QLabel(Form)
@ -67,6 +84,13 @@ class Ui_Form(object):
self.work_status = QtWidgets.QLabel(Form)
self.work_status.setGeometry(QtCore.QRect(406, 520, 121, 21))
self.work_status.setObjectName("work_status")
self.label_4 = QtWidgets.QLabel(Form)
self.label_4.setGeometry(QtCore.QRect(320, 370, 291, 21))
self.label_4.setObjectName("label_4")
self.responseBody = QtWidgets.QTextBrowser(Form)
self.responseBody.setGeometry(QtCore.QRect(320, 390, 291, 121))
self.responseBody.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.responseBody.setObjectName("responseBody")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
@ -83,6 +107,9 @@ class Ui_Form(object):
self.gen_ret_str.setText(_translate("Form", "Сгенерировать"))
self.group_token.setPlaceholderText(_translate("Form", "токен группы"))
self.group_idInput.setPlaceholderText(_translate("Form", "id группы"))
self.loadButton.setText(_translate("Form", "Загрузить"))
self.new_saveButton.setText(_translate("Form", "Сохранить как"))
self.saveButton.setText(_translate("Form", "Сохранить"))
self.start.setText(_translate("Form", "Запуск"))
self.label_2.setText(_translate("Form", "<html><head/><body><p align=\"center\">Запросы</p></body></html>"))
self.requestBody.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
@ -92,4 +119,10 @@ class Ui_Form(object):
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
self.label_3.setText(_translate("Form", "<html><head/><body><p align=\"center\">Тело запроса</p></body></html>"))
self.work_status.setText(_translate("Form", "<html><head/><body><p><img src=\":/response_codes/Sending.png\"/> Сервер не запущен</p></body></html>"))
self.label_4.setText(_translate("Form", "<html><head/><body><p align=\"center\">Ответ</p></body></html>"))
self.responseBody.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
import source_rc

View File

@ -0,0 +1 @@
f1d39232