fureunoir

Untitled

Dec 4th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import sys
  2. import time
  3. import requests as r
  4. from PyQt6.QtWidgets import QApplication, QWidget
  5. from sign_in import SignIn
  6. from flow import Flow
  7. from threading import Thread
  8.  
  9.  
  10. class Client:
  11.     def __init__(self):
  12.         self.app = QApplication(sys.argv)
  13.         self.in_call = False
  14.         self.SignInForm = QWidget()
  15.         self.FlowForm = QWidget()
  16.         self.SignIn = SignIn()
  17.         self.SignIn.setupUi(self.SignInForm)
  18.         self.SignInForm.show()
  19.         self.SignIn.pushButton.clicked.connect(self.initiate_authorization)
  20.  
  21.     def initiate_authorization(self):
  22.         req = r.get('URL_HERE', auth=(self.SignIn.login.text(), self.SignIn.password.text()))
  23.         if req.status_code == 200:
  24.             self.login, self.password = self.SignIn.login.text(), self.SignIn.password.text()
  25.             self.SignInForm.close()
  26.             self.setup_flow()
  27.         else:
  28.             pass
  29.  
  30.     def setup_flow(self):
  31.         self.Flow = Flow()
  32.         self.Flow.setupUi(self.FlowForm)
  33.         self.FlowForm.show()
  34.         self.Flow.pushButton.clicked.connect(self.initiate_call)
  35.         # Here is
  36.         self.flow_cycle = Thread(target=self.flow)                         # the part I'm intested in the most
  37.         self.flow_cycle.setDaemon(True)
  38.         self.flow_cycle.start()
  39.  
  40.  
  41.     # the function with "while: True"
  42.     def flow(self):
  43.         while not self.in_call:
  44.             call = (r.get('https://autovoix.com/api/last-calls', auth=(self.login, self.password)).json())[0]
  45.             called_number = call['called_number']
  46.             self.Flow.label_3.setText(str(call['id']))
  47.             self.Flow.label_4.setText(str(call['status']))
  48.             time.sleep(10)
  49.         self.FlowForm.close()
  50.  
  51.     # the function that I want to stop the first function.
  52.     def initiate_call(self):
  53.         self.in_call = True
  54.  
  55.  
  56. client = Client()
  57. sys.exit(client.app.exec())
Advertisement
Add Comment
Please, Sign In to add comment